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
tgganeshtgganesh 

Dynamic sobject typecasting issue

Hi,

 

I am trying to fetch a field value from a custom object. Currently am storing custom object data in a sObject. when i try to fetch some related field value of custom object. it is throwing me error as invalid field.

 

if i try to fetch field value belongs to custom object, it is providing correctly.

 

for(At_Risk_Request__c AtRiskRecords : mapMainObject.values()) // Taking atRisk record
                {                
                    sObject dynObject= Schema.getGlobalDescribe().get('At_Risk_Request__c').newSObject() ;
                    //At_Risk_Request__c dynObject = new At_Risk_Request__c();
                    
                    dynObject= mapMainObjectData.get(AtRiskRecords.Id);
                    
                                       system.debug('GlobalREgion+++++'+String.valueOf(dynObject.get(CustomerAccount__r.Global_Region__c)));

 At_Risk_Request__c is a Child object and CustomerAccount is parent object (Account).

Bhawani SharmaBhawani Sharma
Just answered on last post