0

I am having a requirement where in i am doing asynchronous calls using REST API. I am using Continuation method to perform the asynchronous calls,but here the callback method is not getting called.

Also i am getting

POST Server (500) error

in visualforce page console.

What might be the issue here?

    //CONTINUATION METHOD 1 (PAPQ API CALL)
    Public object continuationMethod1(){
            system.debug('continuationMethod1 called@@@');
            String dateConverted = '';
            Continuation con; 
            Http h = new Http();
            HttpRequest papqRequest = new HttpRequest();

            try{
                con = new Continuation(120);
                con.continuationMethod = 'continuationMethod2';
                //PAPQ REQUEST *****************************//
                //dateConverted = TW_ParserUtility.dateTimeToDate(customerDetailsToBeFilled.Date_Of_Birth__c);
                Map<String,String> papqParams = new Map<String,String>();
                papqParams.put('PAN','BCVPB2924A');
                papqParams.put('Voter ID','1165830');
                papqParams.put('Driving License','TN7520130008800');
                papqParams.put('Mobile No','9898143852');
                papqParams.put('Passport No','');
                papqParams.put('DOB','05/10/1994');
                if(System.label.Papq_API_Switch_On_Off.toUpperCase() == 'TRUE'){
                    papqRequest = papqInt.prepareRequest(papqParams);
                    system.debug('papqRequest '+papqRequest);
                    PAPQRequestString = papqRequest.getBody();
                    system.debug('PAPQRequestString is : '+PAPQRequestString);  
                    this.PAPQrequestLabel = con.addHttpRequest(papqRequest);
                }

                //PAPQ REQUEST ENDS*****************************//

            }

            catch(Exception ex)
            {
                if(errorMsgBRE == '')
                            {
                                errorMsgBRE='Error occurred in PAPQ API call. Please contact administrator.';
                            }
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Some error occured. Please contact Administrator.'));
                system.debug('Exception at Line '+ex.getLineNumber()+' '+ex);
                System.debug('Exception Details'+ex.getMessage());
            } 
            return con;

        }

//This method is not getting called..
    Public Object continuationMethod2(){
            system.debug('continuationMethod2@@@@');
            HttpRequest ncifRequest = new HttpRequest();
            HttpRequest hunterRequest = new HttpRequest();
            HttpRequest liveLoanRequest = new HttpRequest();
            HttpResponse PAPQresponse;
            Continuation chainedContinuation = NULL;

            try{
                chainedContinuation = new Continuation(120);
                chainedContinuation.ContinuationMethod = 'processNextResult';

                //RESPONSE*******PAPQ RESPONSE**********RESPONSE 
                PAPQresponse = Continuation.getResponse(PAPQrequestLabel);
                PAPQStatusCode = PAPQresponse.getStatusCode();
                this.PAPQresult = PAPQresponse.getBody();
                system.debug('PAPQStatusCode@@@ '+PAPQStatusCode+'PAPQresult '+PAPQresult);
                if(PAPQStatusCode == 200 && String.isEmpty(PAPQresult)){
                    breExceptionMessage('PAPQ',PAPQStatusCode,this.PAPQresult,PAPQWrap,True,'','');    
                }
                else {
                    system.debug('PAPQStatusCode @@@@@@'+PAPQStatusCode);
                    PAPQWrap = (TW_PAPQWrapper)TW_PAPQIntegration.parseResponse(PAPQresult); 
                    system.debug('PAPQWrap@@@@@@'+PAPQWrap);   

                }
            }
            catch(Exception ex)
            {
                if(errorMsgBRE == '')
                            {
                                errorMsgBRE='Error occurred in PAPQ Api call. Please contact administrator.';
                            }
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Some error occured. Please contact Administrator.'));
                system.debug('Exception at Line '+ex.getLineNumber()+' '+ex);
                System.debug('Exception Details'+ex.getMessage());
            } 

                //RESPONSE*******PAPQ RESPONSE ENDS**********RESPONSE//

                //**NCIF REQUEST ********************************//

                if(PAPQWrap.SactionLimit != '0'){
                     try{
                    if(System.label.Ncif_API_Switch_On_Off.toUpperCase() == 'TRUE'){
                        ncifRequest = twNcifInt.prepareRequest('CXTPK7872G');//Harcoded value
                        system.debug('ncifRequest '+ncifRequest);
                        NCIFRequestString = ncifRequest.getBody();
                        system.debug('NCIFRequestString is : '+NCIFRequestString);
                        this.NCIFrequestLabel = chainedContinuation.addHttpRequest(ncifRequest);
                    }
                     }
                    catch(Exception ex)
                        {
                if(errorMsgBRE == '')
                            {
                                errorMsgBRE='Error occurred in NCIF Api call. Please contact administrator.';
                            }
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Some error occured. Please contact Administrator.'));
                system.debug('Exception at Line '+ex.getLineNumber()+' '+ex);
                System.debug('Exception Details'+ex.getMessage());
                     } 
                    //**NCIF REQUEST ENDS ********************************//


                    //**Hunter REQUEST ***********************************//
                    try{
                    if(System.label.Hunter_API_Switch_On_Off.toUpperCase() == 'TRUE'){
                        //hunterRequest = twHunterInt.generateHunterRequest(newopp.Id);
                        hunterRequest = twHunterInt.generateHunterRequest('0069D000001rkq6');
                        system.debug('hunterRequest '+hunterRequest);
                        HunterRequestString = hunterRequest.getBody();
                        system.debug('HunterRequestString is : '+HunterRequestString);
                        this.NCIFrequestLabel = chainedContinuation.addHttpRequest(hunterRequest);
                        //**Hunter REQUEST ENDS ***********************************//
                    }
                    }
                        catch(Exception ex)
                        {
                if(errorMsgBRE == '')
                            {
                                errorMsgBRE='Error occurred in Hunter API call. Please contact administrator.';
                            }
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Some error occured. Please contact Administrator.'));
                system.debug('Exception at Line '+ex.getLineNumber()+' '+ex);
                System.debug('Exception Details'+ex.getMessage());
                         } 



                        //**Live Loan(KB038) REQUEST ***********************************// 
                        try{
                        contactId = [SELECT Contact__c FROM Opportunity where id =:newopp.Id LIMIT 1].Contact__c;
                        Contact conData = [SELECT Party_ID__c FROM Contact where id =:conId LIMIT 1];
                        if(System.label.Live_Loan_API_Switch_On_Off.toUpperCase() == 'TRUE' && String.isNotEmpty(conData.Party_ID__c)){
                            liveLoanRequest = kb038Int.prepareRequest('102136400');   
                            system.debug('liveLoanRequest '+liveLoanRequest);   
                            LiveLoanRequestString = liveLoanRequest.getBody();
                            this.LiveLoanrequestLabel = chainedContinuation.addHttpRequest(liveLoanRequest);
                            system.debug('LiveLoanrequestLabel '+LiveLoanrequestLabel);
                            //**Live Loan(KB038) REQUEST ENDS ***********************************// 
                        }

                }
                    catch(Exception ex)
                        {
                if(errorMsgBRE == '')
                            {
                                errorMsgBRE='Error occurred in live loan API call. Please contact administrator.';
                            }
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Some error occured. Please contact Administrator.'));
                system.debug('Exception at Line '+ex.getLineNumber()+' '+ex);
                System.debug('Exception Details'+ex.getMessage());
            }
                }

                else if(PAPQWrap.SactionLimit == '0'){
                    isSanctionLimitZero = true;        
                }
           return chainedContinuation;



        }

Debug log for the Continuation Method 1..

1
  • Are you able to successfully hit the endpoint from postman? Just checking if there is no issue with callout
    – RedDevil
    Commented May 14, 2019 at 9:23

1 Answer 1

1

The callback method name mentioned in your continuationMethod1 method is processResponse, hence when a response is received it will look for processResponse method which is not available in your class, hence your callback function is not getting called.

If you want your continuationMethod2 method to be used as a callback method for continuationMethod1, then you will have to replace the below code in continuationMethod1 method

con.continuationMethod = 'processResponse';

with

con.continuationMethod = 'continuationMethod2';
5
  • Hi Vijay thanks for the response i am calling with same name only i forgot to change the name edited the code. Commented May 14, 2019 at 9:09
  • And they are totally methods being called..From 'continuationMethod2' i am calling one more method. Commented May 14, 2019 at 9:12
  • Did you set the endpoints for HttpRequest ? I don't see any code, where you are setting the endpoints. If you did, then did you test your service with any other tool? Commented May 14, 2019 at 9:31
  • Yes Vijay i am doing that in prepareRequest call however the issue is solved now there was some problem in my vf page. Commented May 15, 2019 at 5:26
  • Those who might search this post in google..The reason for callback method not calling might be incorrect name as method defined as suggested by Vijay.. Commented May 15, 2019 at 5:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .