Quantcast
Channel: Active questions tagged lightning-experience - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 3018

Database.SaveResult for reteriving all the validation error

$
0
0

I am trying to get all the validation error message from my apex class in to the lightning component. Earlier I was using the DMLException and only one 1 validation error was captured. So I tried to use the Database.SaveResultlike below is my apex Class

@AuraEnabledpublic static String passCase(String caseId){    List<Case> case_recs = [SELECT id,_Case_Flow__c,Status from Case WHERE Id = :caseId];    String msg = '';    for (Case rec : case_recs)    {        rec.Status = 'Transferred';        rec.Route_Case_Flow_Executing__c = true;        Database.SaveResult saves = Database.update(rec, false);            if(!saves.isSuccess()) {                msg = 'Error '+ saves.getErrors()[0].getMessage();            }           else {               msg = 'Successfully Updated!';           }           return msg;         }              return msg;}

And my lightning component looks like below

passCaseToCS_helper : function(c,e,h) {    var set_action1 = c.get("c.passCase");    set_action1.setParams({caseId: c.get('v.recordId')});    set_action1.setCallback(this, function(result)    {        var resultFormApex = result.getReturnValue();        if (result.getState() === 'SUCCESS')            {                               var toastEvent = $A.get("e.force:showToast");                toastEvent.setParams({                    message: resultFormApex ,                    type: 'success',                    mode: 'pester'                });                toastEvent.fire();             }                            else if(result.getState() === 'ERROR')            {                $A.get("e.force:showToast")                        .setParams({                            type: 'error',                            mode: 'pester',                            message: resultFormApex  }).fire();             }        $A.get("e.force:refreshView").fire();    });    $A.enqueueAction(set_action1);       }

When the record successfully gets updated with no Validation error I can see the Successfully Updated!in the toast for the records with Validation error I cannot see anything in the Toast. I tried to put a debug log to show what msg when the record update fails with Validation error I dont see anything on the logs either. I am not sure what I am missing here. Any help is greatly appreciated


Viewing all articles
Browse latest Browse all 3018

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>