+ Start a Discussion

Dynamic sobject typecasting issue



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);

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

Bhawani SharmaBhawani Sharma
Just answered on last post