Skip to main content
1 of 2
Deepak Agarwal
  • 536
  • 2
  • 16
  • 43

Callback method not getting called in Continuation Object

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 = 'processResponse';
                //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..

Deepak Agarwal
  • 536
  • 2
  • 16
  • 43