HomeGuidesDeveloper HubRelease Notes
Get supportBook a chat
Developer Hub

FieloPLT.SegmentService Class

The FieloPLT.SegmentService class includes three methods.

Obtain Member Segments (getMemberSegments)

static Set<Id> FieloPLT.SegmentService.getMemberSegments (Id memberId, Set<Id>segmentIds)

Enables you to obtain information about Segments from a particular Member (Member Segments).

Parameters

ParameterTypeDescription
memberIdIdID of a specific Member.
segmentIdsSet<Id>Optional parameter that evaluates a set of Segments IDs.

Obtain Member Segments (getMemberSegments)

  • Check below an example of how the API can be used:
FieloPLT__Member__c member = [SELECT Id FROM FieloPLT__Member__c LIMIT 1];     
Set<Id> segmentIds = FieloPLT.SegmentService.getMemberSegments(member.Id, null);









Return Value

TypeDescription
Set<Id>Set of Member IDs.
❗️

Cookie storage

The first time the method is executed, it stores Segment values in your browser cookies. Unless Member ID and User session change, the API always returns the value stored in your browser cookies.

Verify Segments (verifySegments)

static void FieloPLT.SegmentService.verifySegments (Map<Id,Set<Id>> segmentsByMember)

It enables you to obtain information about Segments from different Members. You are able to pass a map of Member Id with a Set of Segments and remove from that set any segment where the member doesn't apply to.

For example, if the map name is keepOnlyMemberThatSegmentsApply, and I have a lot of segments there, then you pass keepOnlyMemberThatSegmentsApply to the method SegmentService.verifySegments(keepOnlyMemberThatSegmentsApply) and the service will remove form that list since the members don't belong to it, so now keepOnlyMemberThatSegmentsApply will have only silver.

This method doesn't return anything.

Parameters

ParameterTypeDescription
segmentsByMemberMap<Id,Set<Id>>IDs of Members from Segments to retrieve. The set of Segments IDs that apply for each Member are set as values.

Verify Segments (verifySegments)

  • Check below an example of how the API can be used:
Map<Id, Set<Id>> segmentsByMember = new Map<Id, Set<Id>>();
Set<Id> segmentIds = new Set<Id>();
for(FieloPLT__Segment__c segment : [SELECT Id FROM FieloPLT__Segment__c LIMIT 5]){
   segmentIds.add(segment.Id);
}
for(FieloPLT__Member__c member : [SELECT Id FROM FieloPLT__Member__c LIMIT 5]){
   segmentsByMember.put(member.Id, segmentIds);
}
FieloPLT.SegmentService.verifySegments(segmentsByMember);









Return Value

TypeDescription
VoidVoid.

Obtain Segments (getMetasegmentId)

static Id FieloPLT.SegmentService.getMetasegmentId (Set<Id> segmentIds)

It enables you to obtain information from any Segment, created in any object (either Salesforce standard or a custom object). Some Platform objects already include a relationship to Segments, such as Incentives and Rewards. If you need to relate Segments to other objects, you must previously create a relationship as established in Segments.

Parameters

ParameterTypeDescription
segmentIdsSet<Id>ID of Segments to retrieve.

Return Value

TypeDescription
IdUnique ID which comprises all individual Segment IDs.

Obtain Segments (getMetasegmentId)

  • Check below an example of how the API can be used:
Set<Id> segmentIds = new Set<Id>();
for(FieloPLT__Segment__c segment : [SELECT Id FROM FieloPLT__Segment__c WHERE RecordType.DeveloperName != 'Metasegment' LIMIT 3]){
   segmentIds.add(segment.Id);
}
Id metaSegmentId = FieloPLT.SegmentService.getMetaSegmentId(segmentIds)
📘

WHERE Clause

In order to obtain information about the Members which are included in a specific Segment, send the following query:

String whereClause = [SELECT FieloPLT__WHEREClause__c FROM FieloPLT__Segment__c LIMIT 1][0].FieloPLT__WHEREClause__c;
List<FieloPLT__Member__c> members = Database.query('SELECT Id, Name FROM FieloPLT__Member__c WHERE ' + whereClause);
❗️

Segment Criteria Value

Segment Criteria must include a static Value. Otherwise, if Criteria in Segments includes at least a ticked Field, Value becomes {!FieldName} in the WHERE Clause. Salesforce does not allow direct field to field comparison in a SOQL query, so you must decide how to implement it.
E.g. If Segment Criteria defines that Segment must include Members whose Points are greater than Miles, its WHERE Clause must be FieloPLT__Points__c> {!Miles__c}.