+ Start a Discussion
Julien LussierJulien Lussier 

Question concerning testing @future(callout=true) method that has a query


I'm currently writing a test class for a trigger and I'm a bit stumped. My trigger calls a utility class which has a @future(callout=true) method, in which a soap message is written. In this method there is a query in order to get all the information related to the record and the related records. However, this query always ends up returning null during tests (it works fine otherwise). If I comment out the @future(callout=true) then the query has no issue finding the data. Can someone point me to what I might be doing wrong?

Test class:

public static testMethod void oppTest() {
        User u = Test_HelperMethods.createUser('oTF', 'oTL', p.Id);
        insert u;
        system.runAs(u) {
            Account a = Test_HelperMethods.createPolicyAccount();
            insert a;
            Opportunity opp = Test_HelperMethods.createOpportunity();
            opp.AccountId = a.Id;
            insert opp;
            opp.StageName = 'Committed';
            update opp; //utils method only gets called in afterupdate.

Methods called:

    public static void updateStatus(List < Id > oppIds) {
        String oppId = oppIds[0];
        String soapMessage = prepareSOAPMessage(oppId);
        ... //rest of method goes here

    private static String prepareSOAPMessage(Id oppId){
        OCB_Environment__c re = OCB_Environment__c.getValues('Sandbox');
        system.debug('OppID ='+oppId); //Id gets passed properly
        List<Opportunity> oppList = [SELECT Id FROM Opportunity WHERE Id =: oppId];
        system.debug('oppList: '+ oppList); //this will return empty.

Hi Julien,

Try adding (seeAllData = true) at the top of Test class.

Let me know if you face some issue.

Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990