The 'SobjectFieldPath' class represents the path to the field of Sobject. It effectively allows the necessary data about the target field from the path represented just as a string.
The following are constructors for SobjectFieldPath.
SobjectFieldPath(String sobjectApi, String path)
SobjectFieldPath fieldPath = new SobjectFieldPath('Contact', 'Account.Name');SobjectFieldPath(SObjectType sObjectType, String path)
SobjectFieldPath fieldPath = new SobjectFieldPath(Contact.SObjectType, 'Account.Name');The following are methods for SobjectFieldPath. All are instance methods.
- path
path(): String
Returns field path. Example: Account.Name
System.debug(
new SobjectFieldPath('Contact', 'Account.Name')
.path()
); // account.name- targetReferencePath
targetReferencePath(): String
Returns reference path for target sobject. If sobject is'Contact'and path is'account.name'it returns'account.id'
System.debug(
new SobjectFieldPath('Contact', 'Account.Name')
.targetReferencePath()
); // account.id- targetFieldDescribe
targetFieldDescribe(): String
Returns'DescribeFieldResult'for a target field. The target field is the last field of the path. If sobject is'Contact'and path is'Account.Name'then the target field is'Name'of'Account'
new SobjectFieldPath('Contact', 'Account.Name')
.targetFieldDescribe()