Loading
Prepare for Email to Become the Default Login ExperienceRead More
Get Started with Communications, Media, and Energy & Utilities (CME)...
MSMemberObjectSelector Interface

MSMemberObjectSelector Interface

Supports writing custom query logic for different member types that are configured in the MultiSite Group Management UI. The default implementation reads the field values configured in CPQ Group Member Type records and uses that to query for member records.

This interface supports pre- and post-processing hooks. For information about implementing pre- and post-processing hooks, see .

Namespace

vlocity_cmt

Signature

Loosely typed

global virtual Boolean invokeMethod(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> option)

Default Implementation

MemberObjectSelector Class

Other Implementations

None

Usage

The default implementation is used in the Group Management UI through the getUngroupedRecords API.

Methods

Method

Description

MemberObjectSelector:getMemberObjects Method

Gets a list of member objects and the total number of records.

Example Implementation

This sample implementation shows how the getMemberObjects method is used to get the list of members of the specified type.

global class CustomMemberObjectSelectorImpl extends vlocity_cmt.MemberObjectSelector {
    private static String nsPrefix = 'vlocity_cmt__';

    global override Boolean invokeMethod(String methodName, Map <String, Object> input, Map <String, Object> output, Map <String, Object> option) {
      //set SObject as ServicePoint
      if (input.get('sObjectType') == null) {
        throw new CustomMemberObjectSelectorException('Cannot find Sobject type of member object.');
      }

      if (input.get('onlyTheseFieldList') == null) {
        input.put('onlyTheseFieldList', new List < String > {
          'Id',
          'Name'
        });
      }

      if (methodName.equals('getMemberObjects')) {
        getMemberObjects(input, output, option);
      }

      return false;
    }

    private void getMemberObjects(Map < String, Object > input, Map < String, Object > output, Map < String, Object > option) {
      //Account Hierarchy for ContextId. 
      Set < Id > accountIds = (Set < Id > ) input.get('accountIds');
      //All premises belonging to accounts in :accountIds.
      Set < Id > premisesIds = (Set < Id > ) input.get('premisesIds');
      //If QuoteMemberFieldName__c or OrderMemberFieldName__c columns are not empty, we exclude these members from the query.
      Set < Id > excludeIds = (Set < Id > ) input.get('excludeIds');
      //Fields to query based on Group Object types.
      List < String > fieldList = (List < String > ) input.get('onlyTheseFieldList');
      //Group Object type. Ex:- ServicePoint.
      SObjectType groupObjectType = (SObjectType) input.get('sObjectType');
      String objectName = String.valueOf(groupObjectType);
      //Filter conditions from UI to add in the query.
      String filters = (String) input.get('filters');
      //CpqMemberType__mdt based on Group Object type.
      CpqMemberType__mdt memberType = (CpqMemberType__mdt) input.get('memberTypeMDT');

      List < String > conditionList = new List < String > ();
      if (excludeIds != null) {
        conditionList.add('Id NOT IN :excludeIds');
      }

      if (accountIds != null) {
        String fieldName;
        if (groupObjectType == Account.SObjectType) {
          fieldName = 'Id';
        } 
        /*
        For any other SObjectType, fieldName should be the relationship field name to the Account Object
        Eg: 
        else if (groupObjectType == Employee__c.SObjectType) {
          fieldName = nsPrefix + 'AccountId__c';
        }*/
        if (fieldName != null) {
          conditionList.add(fieldName + ' IN :accountIds');
        }
      }

      if (premisesIds != null) {
        String fieldName;
        if (groupObjectType == ServicePoint__c.SObjectType) {
          fieldName = nsPrefix + 'PremisesId__c';
        } else if (groupObjectType == Premises__c.SObjectType) {
          fieldName = 'Id';
        }

        if (fieldName != null) {
          conditionList.add(fieldName + ' IN :premisesIds');
        }
      }

      if (String.isNotBlank(filters)) {
        conditionList.add('(' + filters + ')');
      }

      if (memberType != null) {
        String recordType = (String) memberType.get(nsPrefix + 'RecordType__c');
        if (String.isNotBlank(recordType)) {
          conditionList.add('RecordType.DeveloperName = :recordType');
        }
        String recordFilters = (String) memberType.get(nsPrefix + 'RecordFilters__c');
        if (String.isNotBlank(recordFilters)) {
          conditionList.add('(' + recordFilters + ')');
        }
      }

      String conditions = '';
      if (!conditionList.isEmpty()) {
        conditions = String.join(conditionList, ' AND ');
        input.put('queryCondition', conditions);
      }

      output.put('records', Database.query(getQuery(input, null, null)));

      //Boolean field to either return TotalCount or not.
      Boolean getTotalCount = (Boolean) input.get('getTotalCount');
      if (getTotalCount != null && getTotalCount) {
        String query = 'Select count() From ' + objectName;
        if (String.isNotBlank(conditions)) {
          query += ' Where ' + conditions;
        }
        output.put('totalCount', Database.countQuery(query));
      }
    }

    public String getQuery(Map<String, Object> input, Map<String, Object> output, Map<String, Object> options)
    {	
	//Add a SOQL query string to fetch the Group Object
	String soqlQueryToFetch = '';
        return soqlQueryToFetch;
    }

    global class CustomMemberObjectSelectorException extends Exception {}
}
 
Loading
Salesforce Help | Article