0

I (seemed to) have sucessfully passed an object from the client side helper controller into the apex method. However i am having trouble accessing using the dot notation i am used to in javascript and with queried objects in apex methods

Helper

fetchUpdaterHelper : function(component, event, helper) {
    var action = component.get("c.updatePolicyValues");
    var why = component.get('v.initialRetrieve')[0];

    action.setParams({ 
        "rId": component.get("v.policyrecordID"),
        "sObj" : why});


    $A.enqueueAction(action);
}

Apex Method

@AuraEnabled
 public static void updatePolicyValues (String rId, Map<String, Object> 
 sObj) {
   Policies__c ValuestoUpdate = [SELECT Premium_Amount_RV__c, 
Cash_Surrender_Value_RV__c, Gross_Death_Benefit_RV__c, 
Values_as_of_RV__c FROM Policies__c WHERE Id = :rId]; 

   ValuestoUpdate.Gross_Death_Benefit_RV__c = 405000;
   System.debug(sObj);

   update ValuestoUpdate;
}

confirmation the object made it into the apex method picture of debug log

what is the syntax to access the values within the passed in sObj parameter? sObj.keyvalue does not seem to be working

1 Answer 1

3

Because your sObj is of type Map<String, Object>, so to access the values within the map, you will need to fetch the values based on the key.

As an example (as in your screenshot), to fetch the value of AV_Cash_Surrender_Value__c, you will write:

Object val = sObj.get('AV_Cash_Surrender_Value__c');

The Object depends on the type of the value, so if the above value is say an Integer, you can write it as:

Integer val = (Integer) sObj.get('AV_Cash_Surrender_Value__c');
1
  • Glad that it helped you @Bobbygllh
    – Jayant Das
    Commented Mar 22, 2019 at 15:48

You must log in to answer this question.

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