function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chaithaly gowdachaithaly gowda 

sObj.getSObject(parentfield) is returning NULL


I am running this generic code which is used to return set of ID.

public statset<id>getetIdSet(sObject[] pSobjects, string pSObjField){
        set<Id> sObjIdSet = new set<Id>();
        for(sObject sObj : pSobjects){
            if(pSObjField != null){
                //split reference fields
                string[] refFields = pSObjField.split('\\.');
               if(refFields.size() > 1){
                    if(sObj.getSObject(refFields[0]) != null && sObj.getSObject(refFields[0]).get(refFields[1]) != null){                       
return sObjIdSet;
getIDset(newContacts, 'reference_field__r.field__c');
System.debug( sObj.getSObject(refFields[0])); this statement is returning NULL even though there is value in both the field.

Can someone please help regarding this issue . how to access parent fields when running from child trigger context.
Hi Chaitantya ,
Check if this is work for you  , else  please eleborate more about the issue :
public set<id> getetIdSet(sObject[] pSobjects, ){
set<Id> sObjIdSet = new set<Id>();
    for(Sobject sObj: pSobjects) {
return sObjIdSet;