0

I am trying to use an Apex Class I found at this link: https://automationchampion.com/2020/12/01/getting-started-with-process-builder-part-50-auto-convert-leads/ Here is the Apex Class:

Public class AutoConvertLeads 
{     @InvocableMethod   
    public static void LeadAssign(List<Id> LeadIds)  
    {         
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];    
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();    
        for(id currentlead: LeadIds){                
            Database.LeadConvert Leadconvert = new Database.LeadConvert();    
            Leadconvert.setLeadId(currentlead);                               
            Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);             
            Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion  
            MassLeadconvert.add(Leadconvert);    
        }                  
        if (!MassLeadconvert.isEmpty())
        {            
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);       
        }    
    } 
}

Here is the Test Class

@isTest 
      public class TestAutoConvertLeads{
      static testMethod void createnewlead() {
      User userToCreate = [Select id from user where profile.name='System Administrator' Limit 1];
      
      Test.startTest();    
      Lead leadToCreate =new Lead();
      List<id> Ids= New List<Id>();
      leadToCreate.ownerid= userToCreate.id;
      leadToCreate.LastName ='Gupta';
      leadToCreate.Company='Salesforce';
      leadToCreate.LeadSource='Partner Referral';
      leadToCreate.Rating='';
      leadToCreate.Status='';
      insert leadToCreate; 
      
      Ids.add(leadToCreate.id);
      AutoConvertLeads.LeadAssign(Ids);
      
      Test.stopTest();
   }
}

Here is the error I get when trying to bring in the Inbound Change set to my production org when running the Test Class test:

createnewlead - - - Methods defined as TestMethod do not support Web service callouts Stack Trace: null

0
1

You have a trigger that's trying to make a callout asynchronously. You'll need to set up some kind of callout mock, as mentioned in the documentation. This might be in your own code or in an installed managed package. Reading the debug logs from running the unit test will help. In other words, the problem isn't specifically this unit test, which would work in another org, but rather caused by your specific org's configuration.

1
  • Thank you very much sfdcfox - turns out your comment helped me figure out wtf was happening. I am dumb :( Read through the debug log and found an old managed package, we haven't used in years, still in there that was tossing this out. Got it fixed! Thanks for the help! Jan 10 at 20:35

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