-
Notifications
You must be signed in to change notification settings - Fork 0
How To & Examples
Jason Auger edited this page Nov 29, 2020
·
2 revisions
SObjectHelper accountHelper = new SObjectHelper('Account');
SObjectHelper customObjectHelper = new SObjectHelper('MyCustomObject__c');
For the main SObject that the helper has been initiated with, this will return all fields for only that object:
String accountFields = accountHelper.selectAllString;
To get fields for all or specific objects that have Lookups or Master-Detail Lookups on this SObject:
String contactFieldsOnAccount = accountHelper.createQueryStringForRelatedSObject('ContactId');
String customObjectFieldsOnAccount = accountHelper.createQueryStringForRelatedSObject('CustomObject__c');
You can group multiple objects at time in a Set or List
List<String> sobjs = new List<String>{'ContactId', 'CustomObject__c'};
String queryString = accountHelper.createQueryStringForRelatedObjects(sobjs);
Example
SObjectHelper contractHelper = new SObjectHelper('Contract');
Set<String> testSet = new Set<String>{'AccountId', 'CustoObj__c'};
String queryString = '';
queryString += 'SELECT ' + contractHelper.selectAllString + ',\n';
queryString += contractHelper.createQueryStringForRelatedSObjects(testSet) + '\n';
queryString += ' FROM Contract';
List<SObject> theResults = Database.query(queryString);