function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bhupesh Kumar 14Bhupesh Kumar 14 

Queueable future method

Hi,
I'm facing one issue while executing tests for Queueable future method. When I runing my code using debugging tool on developer console then my code is running successfully. however test is failing. After analysins this it is found that the test class is not able to execute the future method which is being called in Queueable class. Anyone have any idea? 
 
public class CustomClass {
    
    public static void calloutServiceMethod(List<InputParams> inputParams) {      
        cuatomConfig__c configObject = getConfig(inputParams[0].configName);
        System.enqueueJob(new QueueableCall(configObject, inputParams[0].Ids));
    }
    
   
    @Future(callout=true)
    private static void postCall(String configName, List<Id> ids) {
        //some code here that is not being called
    }  
    
    class QueueableCall implements System.Queueable, Database.AllowsCallouts {
        private cuatomConfig__c configuration;
        private List<id> IDS;
        public QueueableCall(cuatomConfig__c Configuration, List<Id> ids){
          this.configuration = Configuration;
          this.IDS = ids;
        }
        public void execute(QueueableContext context) {
            String CName = configuration.Name__c;
            postCall(CName, IDS);
        }
    }
    
     public class InputParams {   
        
        public List<Id> Ids;
        public String configName;
    }
    
}

 
Ugur KayaUgur Kaya
Hi Bhupesh,

Did you try initiating this test execution which has the @future method call between Test.start() and Test.stop()?

https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_future_methods

 
Bhupesh Kumar 14Bhupesh Kumar 14
Hi Ugur, 

Yes, My test class is like below:
 
@isTest
    static void testPostCalloutSuccess() {
        Opportunity opp = [Select Id, Name FROM Opportunity WHERE Name = 'Oppo 1' Limit 1];
        List<Id> oppList = new List<Id>();
        oppList.add(opp.Id);
        System.assertEquals('Oppo 1', opp.Name);
        System.assertEquals(1,oppList.size());
        Test.startTest();
        
        Test.setMock(HttpCalloutMock.class, new CustomClassMock()); 
       
        String configName = 'config2';
        CustomClass.InputParams inputParam = new CustomClass.InputParams();
        inputParam.configName = configName;
        inputParam.Ids = oppList;
        
        List<CustomClass.InputParams> inputParams = new List<CustomClass.InputParams>();
        inputParams.add(inputParam);
        
        CustomClass.calloutServiceMethod(inputParams);
       
        Test.stopTest();  
        connConfig__c confAfterupdate = [SELECT Status__c from connConfig__c where Name__c = :configName];
		System.assertEquals('Success' ,confAfterupdate.Status__c);
    }