1

I'm creating a map in javascript I have a key as String and Value as SObject here is the function for the map

var oMap = {};
function addValueToKey(key, value) {
    oMap[key] = finAccountMap[key] || [];
    oMap[key].push(value);
}
 addValueToKey('Blue',accOne);
 addValueToKey('Green',accTwo); 

then I JSON.stringify the map then I pass the map to apex controller as String Json

@AuraEnabled public static List<FinAccount__c > actionUpdateFinAccount(String oMapJson) {
     Map<String, Object> accMap = (Map<String, Object>)JSON.deserializeUntyped(oMapJson);

     for (String key : accMap.keySet()){
          System.debug('field name is ' + key);
          Object  accObj = accMap.get(key);
          System.debug(accObj);
          System.debug(accObj.Id);
      }
 }

the problem is that I will get error if I do accObj.Id which is

Variable does not exist: Id

after the deserialize my data will look like this

{Blue=({Account__c=0011D00000GabRNQAZ, Id=a061D000001BI7lQAG,  Name=color}), Green=({Account__c=0011D00000GabRNQAZ, Id=a061D000001BI7HQAW, Name=color})}

also System.debug(accObj); will look like this

({Account__c=0011D00000GabRNQAZ, Id=a061D000001BI7HQAW, Name=color})
1
  • I believe you need to cast accObj to an account
    – EricSSH
    Jun 5, 2018 at 22:52

2 Answers 2

2

You can cast it

Account accObj = (Account) accMap.get(key);
System.debug(accObj);
System.debug(accObj.Id);
1

You should get field value dynamically like this:

sObject.get('Id')

In your case it would be

AccObj.get('Id')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .