1

I have an invocable method with varables. I am stuck how to set these in unittest

Class

    public class or_service {    

    public class invoceVars{
        @InvocableVariable
        public id pIds;

        @InvocableVariable
        public String uid;
    }

    @InvocableMethod
    public static void Invoce(List<invoceVars> iVs) {

       ..
    } 
}

Unittest

 @isTest
private class or_serviceTest {

    private static testMethod void callFutureMethodPostProperty() {        
        Orbirental_Service__c  setting = new Orbirental_Service__c(ApiKey__c = '0000000000000',Url__c = 'http://test.com/'
                                                                   ,agencyUid__c = '0000-0000-0000-0000-0000');
        insert setting;

        Property__c prop = new Property__c(Name__c = 'test');
        insert prop;

        List<String> str = new List<string>{prop.id,prop.uid__c};
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new or_propertiesHttpMock());
        or_service.invoce(str);  
        Test.stopTest();
    }
}
2

I came up with this solution :

@isTest
private class or_serviceTest {

    private static testMethod void callFutureMethodPostProperty() {        
       Orbirental_Service__c  setting = new Orbirental_Service__c(ApiKey__c = 
      '0000000000000',Url__c = 'http://test.com/',agencyUid__c = '0000-0000- 
       0000-0000-0000');
       insert setting;

      Property__c prop = new Property__c(Name__c = 'test');
      insert prop;

      List<or_service.invoceVars> invoiceVariables = new List<or_service.invoceVars>();
    or_service.invoceVars invVar = new or_service.invoceVars();
     invVar.pIds = prop.id;
     invVar.uid = prop.uid__c;
     invoiceVariables.add(invVar);
     Test.startTest();
     Test.setMock(HttpCalloutMock.class, new or_propertiesHttpMock());
     or_service.invoce(invoiceVariables);  
     Test.stopTest();
  }
}
1
  • @progati Thanks for the solution!. Please edit the following and I will accept the answer: invoiceVariables.add(invVar);
    – Thomas
    Oct 13 '18 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.