You need to sign in to do that
Don't have an account?
Eldon
Passing sobject instances from JScontroller to apex and upserting them.
Hi,
I have an attribute named 'cart' which is of type mycart__c(custom object) in my component and i get it using
cartJS=component.get("v.cart"); in my js controller.
Now i am trying to pass it to my apex class using
var action3=component.get("c.getOldcart");
action3.setParams({ "currentcart" : cartJS});
where getOldcart is my apex function.
@auraenabled
public static void getOldcart (list<mycart__c> currentcart){
system.debug('currentcart'+currentcart);
for(mycart__c singleitem:currentcart){
system.debug('singleitem'+singleitem);
}
}
I am getting the values in my currentcart when i debug but when i iterate through it i am getting the following error,
" FATAL_ERROR System.UnexpectedException: Salesforce System Error: 612434560-135286 (152924272) (152924272)"
Is there anything wrong in the above codes?
I have an attribute named 'cart' which is of type mycart__c(custom object) in my component and i get it using
cartJS=component.get("v.cart"); in my js controller.
Now i am trying to pass it to my apex class using
var action3=component.get("c.getOldcart");
action3.setParams({ "currentcart" : cartJS});
where getOldcart is my apex function.
@auraenabled
public static void getOldcart (list<mycart__c> currentcart){
system.debug('currentcart'+currentcart);
for(mycart__c singleitem:currentcart){
system.debug('singleitem'+singleitem);
}
}
I am getting the values in my currentcart when i debug but when i iterate through it i am getting the following error,
" FATAL_ERROR System.UnexpectedException: Salesforce System Error: 612434560-135286 (152924272) (152924272)"
Is there anything wrong in the above codes?
Also, I have noticed that I get such errors when passing anything other than primitives to apex controllers. So, the way to saolve this is, JSON.stringify your obejct and pass to controller as a string. Then, in your apex controller, use JSON.deserializeStrict
So, in your case (assuming that 'cart' is of type 'mycart__c[]':
var action3=component.get("c.getOldcart");
action3.setParams({ "currentcart" : JSON.stringify(cartJS)});
@auraenabled
public static void getOldcart (String currentcart){
system.debug('currentcart'+currentcart);
List<mycart__c> carts = (List<mycart__c>)System.JSON.deserializeStrict(currentcart, List<mycart__cr>.Class);
for(mycart__c singleitem: carts){
system.debug('singleitem'+singleitem);
}
}
Let me know if that works