I Have a lightning component from which I pass data to an apex class. I return the object. Why don't I get an update on my object neither a response in my lightning component.
Lightning
updatePicklist : function(component,event,helper){
var selectedValues = $('[id$=picklist]').select2("val");
var field = component.get("v.fieldName");
var object = component.get("v.objectName");
var getCurrentRecord = component.get("v.recordId");
var action = component.get("c.updateRecord");
action.setParams({
"objId": getCurrentRecord,
"objNew": object,
"selection" : selectedValues,
"fieldName" : field
});
action.setCallback(this, function(response) {
if (response.getState() == "SUCCESS") {
alert('record Updated Successfully-->' + JSON.stringify(response.getReturnValue()));
//Fire the refresh view event to update detail view
$A.get('e.force:refreshView').fire();
}
});
$A.enqueueAction(action);
}
Apex
@AuraEnabled
public static sObject updateRecord(string objNew, id objId , string selection, string fieldName){
sObject sObj = Schema.getGlobalDescribe().get(objNew).newSObject(objId) ;
sObj.put(fieldName , selection) ;
update sObj ;
return sObj;
}
Logging
16:22:13.0 (161658)|CODE_UNIT_STARTED|[EXTERNAL]|Aura
16:22:13.0 (1468788)|CODE_UNIT_STARTED|[EXTERNAL]|01p1l0000008UC9|select2TestCtrl.updateRecord(String, Id, String, String)
16:22:13.0 (1708031)|SYSTEM_MODE_ENTER|false
16:22:13.0 (1828648)|USER_DEBUG|[19]|DEBUG|null null null null
16:22:13.0 (14355318)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
Class.select2TestCtrl.updateRecord: line 20, column 1
16:22:13.0 (14381632)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
Class.select2TestCtrl.updateRecord: line 20, column 1
16:22:13.0 (14398622)|CODE_UNIT_FINISHED|select2TestCtrl.updateRecord(String, Id, String, String)
16:22:13.0 (18207207)|CODE_UNIT_FINISHED|Aura
16:22:13.0 (19271021)|EXECUTION_FINISHED