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"