You need to sign in to do that
Don't have an account?
@AuraEnabled webservice..... action.setCallback not firing
The task is convert a classic button into lightning action. The existing apex controller is unchanged except for adding @AuraEnabled for webservice that will return a list to the client side controller. There are 3 scenarios - the client side controller will alert based on the message received from the apex controller:
There are 2 failure scenarios – able to display them as alerts
There is 1 success scenario – The alert is not triggering for this case.
Apex controller:
global without sharing class giftBatchHelper {
public boolean tagPendingGifts(Id BatchId){
boolean ret = true;
this.errorDesc = '';
this.numOpps = 0;
try{
if (string.isNotBlank(BatchId)){
List<Opportunity> lstOppCheck = [select Id from Opportunity where Gift_Batch__c = :BatchId];
if (lstOppCheck != null)
if (lstOppCheck.size() > 0) {
this.errorDesc = 'This batch already has Gifts assigned. You may not run the batch assignment process more than once for a given Gift Batch.';
ret = false;
return ret;
}
this.errorDesc = 'There are no Posted Opportunities without a Gift Batch assignment.';
List<Opportunity> lstOppUPdate = [select Id, Gift_Batch__c from Opportunity where Gift_Batch__c = null AND StageName = 'Posted' AND RecordType.Name = 'Donation'];
if (lstOppUPdate != null)
if (lstOppUPdate.size() > 0) {
for (Opportunity o: lstOppUPdate )
o.Gift_Batch__c = BatchId;
Update lstOppUPdate;
this.numOpps = lstOppUPdate.size();
this.errorDesc = '';
}
}
}
catch(Exception exc){
this.errorDesc = exc.getMessage();
ret = false;
}
return ret;
}
@AuraEnabled
webservice static list<string> TagPendingGiftsForBatch(string strBatchId){
Id BatchId = Id.valueOf(strBatchId);
if (BatchId ==null) return new list<string>{'Error: Invalid Batch Id',''};
giftBatchHelper objgiftBatchHelper = new giftBatchHelper();
objgiftBatchHelper.tagPendingGifts(BatchId);
return new list<string>{objgiftBatchHelper.errorDesc,string.valueOf(objgiftBatchHelper.numOpps)};
}
}
Client side controller:
({
"echo" : function(cmp) {
// create a one-time use instance of the serverEcho action
// in the server-side controller
var action = cmp.get("c.TagPendingGiftsForBatch");
var varRecordId = cmp.get("v.recordId");
//alert('varRecordId: ' + varRecordId);
action.setParams({ strBatchId : varRecordId });
//alert('before callback');
action.setCallback(this, function(response) {
alert('inside call back');
var result = response.getReturnValue();
//if(response.getReturnValue() != null)
alert('result[0] ' + result[0]);
alert('result[1] ' + result[1]);
if(result[1]==0)
{
var result = response.getReturnValue();
//var retMessage = result[0];
//alert('result[1] ' + result[1]);
//alert('result[0].length ' + result[0].length);
//alert('result.length' + result.length);
if(result.length === 2)
{
if(result[0].length > 0)
{
alert(result[0]);
}
}
}
else if(result[1]>0)
{
alert('Gift(s) updated with batch:');
}
else
{
alert('Error: Batch Id is empty.');
}
});
$A.enqueueAction(action);
$A.get("e.force:closeQuickAction").fire();
}
})
The bold italics section should work when there is a value in result[1] - however, the flow is getting inside the setCallback i.e. the alert('inside call back'); doesn't throw the alert.
Please let me know where there issue is...
The bold italics section should work when there is a value in result[1] - however, the flow is NOT getting inside the setCallback i.e. the alert('inside call back'); doesn't throw the alert.
Please let me know where the issue is...