I am trying to populate a field with the value of another field dynamically based on custom metadata types.
I use the method variable.put(fieldAPIName, value)
in order to populate the fields.
Here is an example of my custom metadata types
Basically, I need to copy the value from the 'From Field' to the 'To Field' based on the metadata.
As you can see in the example, the from field contains a reference field that I am not able to pass to the to field. I get the error "Invalid field csordtelcoa__Replaced_Product_Configuration__r.cscfga__originating_offer__c for cscfga__Product_Configuration__c"
.
My code is like this:
for(cscfga__product_configuration__c parentConfig: csConfigs){
for(el_Change_Request_Mappings__mdt tmpCMT : changeMappings){
parentConfig.put(tmpCMT.To_Field__c, parentConfig.get(tmpCMT.From_Field__c));
}
}
My csConfigs list is an SOQL and the result is this:
Select Id, csordtelcoa__Replaced_Product_Configuration__r.cscfga__originating_offer__c,el_Current_Offer__c,cscfga__originating_offer__c,el_Previous_Offer__c , cscfga__Parent_Configuration__c from cscfga__product_configuration__c where id in: clonedIds
The parentConfig
variable is just an outside iteration containing another for loop. Any thoughts of how I could accomplish it?
parentConfig
ansObject
and you are attempting to get a value from a reference namedcsordtelcoa__Replaced_Product_Configuration__r
? If so, I suggest you to look intogetSObject(fieldName)
which means you first will grab the reference and then the field (which seems to becscfga__originating_offer__c
.