
Hi guys, I am trying to build a process on salesforce to automatically convert lead when a custom field is changed to "Subscribed". I have loaded the code for both my apex and test class on sandbox and have uploaded it to production. Now i have to deploy my apex but it's not working. It says Variable does not exist Line 18, Column 7. Haven't been exposed to Apex, or programming language, but we really need to get this to work. Please advise.
@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();}}
How do i get it to work? What is the next step forward? I will need to deploy this apex class as well but it does not have enough code coverage.
Public class AutoConvertLeads
{ @InvocableMethod public static void LeadAssign(List<Id> LeadIds) { LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatusWHERE IsConverted=true Limit 1]; List<Database.LeadConvert> MassLeadconvert = newList<Database.LeadConvert>(); for(id currentlead: LeadIds){ Database.LeadConvert Leadconvert = newDatabase.LeadConvert(); Leadconvert.setLeadId(currentlead); Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel); MassLeadconvert.add(Leadconvert); } if (!MassLeadconvert.isEmpty()) { List<Database.LeadConvertResult> lcr =Database.convertLead(MassLeadconvert); } }}Hi Ray,remove CheckLead__c on above class :
ThanksVaraprasadFor Support: varaprasad4sfdc@gmail.comLead lead_Obj = new Lead(LastName = 'LastName253', Company = 'Company848', Status = 'Open - Not Contacted', IsConverted = false, IsUnreadByOwner = false);
Insert lead_Obj;
Lead lead_Obj1 = new Lead(LastName = 'LastName254', Company = 'Company888', Status = 'Open - Not Contacted', IsConverted = false, IsUnreadByOwner = false);
Insert lead_Obj1;