FieloPLT.AgreementService class includes two methods.
Obtain Current Agreement (getCurrentAgreement)
static FieloPLT__Agreement__c FieloPLT.AgreementService.getCurrentAgreement (Id programId, Set<String> fieldNames)
Agreement sets the terms and conditions that members need to accept in order to take part in a program. This API allows you to obtain the Agreement with status set as current that belongs to a specific program.
Parameters
Here you'll find an example of how the API can be used and a definition of it's parameters:
Id programId = [SELECT Id FROM FieloPLT__Program__c LIMIT 1].Id;
Set<String> fields = new Set<String>{'Id', 'FieloPLT__Status__c', 'FieloPLT__Agreement__c', 'FieloPLT__Promotion__c','FieloPLT__Challenge__c'};
FieloPLT__Agreement__c agreement = FieloPLT.AgreementService.getCurrentAgreement(programId, fields);| Parameter | Type | Description | Required |
|---|---|---|---|
| programId | Id | ID of the program the agreement is part of. | x |
| fieldNames | Set<String> | List of API names from agreement fields to query. | x |
| fieldNames/ Id | String | ID of the active agreement linked to the program. | |
| fieldNames/ FieloPLT__Status__c | String | Status of the agreement. | |
| fieldNames/ FieloPLT__Agreement__c | String | Name of the agreement. |
Return Values
Here you'll find an example of what is returned in the call and a definition of it's values:
FieloPLT__Agreement__c:{FieloPLT__Status__c=Current, FieloPLT__Agreement__c=TermsofService, Id=a020W00000Jp29XQAR}| Parameter | Type | Description |
|---|---|---|
| FieloPLT__Agreement__c | Set<String> | Current Agreement from the specific program. |
| FieloPLT__Agreement__c/ FieloPLT__Status__c | String | Status of the agreement. |
| FieloPLT__Agreement__c/ FieloPLT__Agreement__c | String | Name of the agreement. |
| FieloPLT__Agreement__c/ Id | String | ID of the active agreement linked to the program. |
Exceptions
Errors can occur when you use the endpoint. Use the message description to troubleshoot them.
FieloPLT.FieloException: Program does not have a "Current" Agreement available.| Type | Description |
|---|---|
| FieloException | No agreement available. Make sure you have an available agreement. |
| FieloException | Agreement status is set to Draft. Make sure the agreement status is set to "Current". |
Accept Agreement (acceptAgreement)
public static Boolean acceptAgreement(Id agreementId, Id memberId, Id recordId)
Use this API when you want your members to accept an agreement before registering to an specific program or before enrolling in a promotion or a challenge. It will relate a member with either a program agreement with the status set as current or an incentive agreement with the status set as current.
Parameters
| Parameter | Type | Description |
|---|---|---|
| agreementId | Id | ID of the Agreement. You can get this information using the the previously mentioned API Obtain Agreement (getCurrentAgreement). |
| memberId | Id | Member ID. |
| recordId | Id | ID of the record, such as a program id, a promotion id or a challenge id. |
Return Value
| Type | Description |
|---|
try{
Boolean agreed = true;
if(agreementId != null) {
agreed = AgreementService.acceptAgreement(agreementId, memberId, recordId);
}
if(agreed && type == 'challenge') {
ChallengeMember__c challengeMember =
FieloPLT.ChallengeService.subscribeToChallenge(memberId, incentiveId);
}
return true;
} catch(DMLException e) {
throw new AuraHandledException(e.getDMLMessage(0));
} catch(Exception e){
throw new AuraHandledException(e.getMessage());
}