Last active
November 7, 2019 23:48
-
-
Save shinchit/7c05aceeb24b8e8aaf97d8c658eb77f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void someMethod() { | |
List<SObject> sobjs = [ | |
SELECT | |
Id, | |
Name, | |
AccountId, | |
Account.Name, | |
SomeCustom__r.Id, | |
SomeCustom__r.Name | |
FROM | |
Opportunity | |
]; | |
Schema.DescribeFieldResult fieldResult = null; | |
Schema.SObjectField field = null; | |
/* print Opprutunity.Id and Opportunity.Name */ | |
System.debug(sojbs); | |
/* print Account.Id and Account.Name */ | |
fieldResult = Schema.Opportunity.Account.getDescribe(); | |
field = fieldResult.getSObjectField(); | |
System.debug(sobjs.getSObject(field)); | |
// or | |
System.debug(sobjs.getSObject('Account')); | |
/* print SomeCustom__c.Id and SomeCustom__c.Name */ | |
fieldResult = Schema.Opportunity.SomeCustom__c.getDescribe(); | |
field = fieldResult.getSObjectField(); | |
System.debug(sobjs.getSObject(field)); | |
// or | |
System.debug(sobjs.getSObject('SomeCustom__r')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment