You need to sign in to do that
Don't have an account?

Pass List <object> from lightning to apex
Hello,
I want to pass an object from my lightning js to my class apex.
My class apex:
@AuraEnabled
public static void updateEntityInfos(string entityWrapperList, String year) {
List<Opportunity> opportunityList = new List<Opportunity>();
opportunityList =(List<Opportunity>)System.JSON.deserialize(entityWrapperList, List<Opportunity>.class);
...
}
In my debug log I have in entityWrapperList :
[{"b2b":0,
"globalObjective":"56"
,"name":"test1"
,"newBusiness":"05"
,"opportunityId":"0065E00000CDMurQAH"
,"others":0,
"turnover":672},
{"b2b":0,
"globalObjective":"05"
,"name":"test2"
,"newBusiness":"05"
,"opportunityId":"0065E00000CDMuqQAH"
,"others":0,
"turnover":60},
{"b2b":0,
"globalObjective":"05"
,"name":"test3",
"newBusiness":"50",
"opportunityId":"0065E00000CDMupQAH"
,"others":0,
"turnover":60},
{"b2b":0
,"globalObjective":"65"
,"name":"test4"
,"newBusiness":"05"
,"opportunityId":"0065E00000CDMuoQAH"
,"others":0,
"turnover":780}]
but in my opportunityList I have just the name:
opportunityList (Opportunity:{Name=EMEA RUSSIE},
Opportunity:{Name=APAC},
Opportunity:{Name=Grande Chine},
Opportunity:{Name=Ameriques})
Can someone help me.
I want to pass an object from my lightning js to my class apex.
My class apex:
@AuraEnabled
public static void updateEntityInfos(string entityWrapperList, String year) {
List<Opportunity> opportunityList = new List<Opportunity>();
opportunityList =(List<Opportunity>)System.JSON.deserialize(entityWrapperList, List<Opportunity>.class);
...
}
In my debug log I have in entityWrapperList :
[{"b2b":0,
"globalObjective":"56"
,"name":"test1"
,"newBusiness":"05"
,"opportunityId":"0065E00000CDMurQAH"
,"others":0,
"turnover":672},
{"b2b":0,
"globalObjective":"05"
,"name":"test2"
,"newBusiness":"05"
,"opportunityId":"0065E00000CDMuqQAH"
,"others":0,
"turnover":60},
{"b2b":0,
"globalObjective":"05"
,"name":"test3",
"newBusiness":"50",
"opportunityId":"0065E00000CDMupQAH"
,"others":0,
"turnover":60},
{"b2b":0
,"globalObjective":"65"
,"name":"test4"
,"newBusiness":"05"
,"opportunityId":"0065E00000CDMuoQAH"
,"others":0,
"turnover":780}]
but in my opportunityList I have just the name:
opportunityList (Opportunity:{Name=EMEA RUSSIE},
Opportunity:{Name=APAC},
Opportunity:{Name=Grande Chine},
Opportunity:{Name=Ameriques})
Can someone help me.
This is happening because during deserialization 'Name' field is the only field that is common between your JSON object and Opportunity object, so only the 'name' in JSON object gets mapped to the name field of opportunity object.
Thanks.
If I understand correctly, to display all the values, you have to name the fields of the entity constructor identical to the field of the Opportunity object?
I proceeded as follows but I receive an error:
"Invalid character in identifier: Objectif_Global_Zone__c"
You will need to modify your code something like this:
Let me know if it helps.
Thanks!
I implemented this code but I have s fatal error in line
ObjList =(List<EntityWrapperClass>)System.JSON.deserialize(entityWrapperList,List<EntityWrapperClass>.class);
I am tried running the same code, and it is giving no error. It is giving results as expected. Maybe someother part of your code is causing this error.
Otherwise there is no reason, it shouldn't work.
If you could send me the whole code I might be able to help you with the error.
in py debug log I have my entityWrapperList :
entityWrapperList = [{"name":"1","Objectif_Global_Zon":"4","ObjZoneEuro_c":48,"opportunityId":"0065E00000CDMurQAH","Zone_Major_Account":"04","Zone_New_Business":"04","Zone_Other":0},
{"name":"2","Objectif_Global_Zon":"04","ObjZoneEuro_c":48,"opportunityId":"0065E00000CDMuqQAH","Zone_Major_Account":"04","Zone_New_Business":"40","Zone_Other":0},
{"name":"3","Objectif_Global_Zon":"04","ObjZoneEuro_c":48,"opportunityId":"0065E00000CDMupQAH","Zone_Major_Account":"04","Zone_New_Business":"04","Zone_Other":0},
{"name":"4","Objectif_Global_Zon":"04","ObjZoneEuro_c":48,"opportunityId":"0065E00000CDMuoQAH","Zone_Major_Account":0,"Zone_New_Business":"04","Zone_Other":0}]
and my OpportunityList:
o = (Opportunity:{Name=1, Objectif_Global_Zone__c=null, Zone_New_Business__c=null, Zone_Major_Account__c=null, Zone_Other__c=null},
Opportunity:{Name=2, Objectif_Global_Zone__c=null, Zone_New_Business__c=null, Zone_Major_Account__c=null, Zone_Other__c=null},
Opportunity:{Name=3, Objectif_Global_Zone__c=null, Zone_New_Business__c=null, Zone_Major_Account__c=null, Zone_Other__c=null},
Opportunity:{Name=4, Objectif_Global_Zone__c=null, Zone_New_Business__c=null, Zone_Major_Account__c=null, Zone_Other__c=null})
The reason you are getting NULL values is because may be you are not assigning values to opportunity fields.
In your for loop assign values to opportunity object like this: