You need to sign in to do that
Don't have an account?
aswin balaji
Test class for auto lead conversion
This is the code of auto lead conversion and autoLeadConversion is the function.I had written master class so i need specific function to be tested
public class AAAExisting{ public List<wrapLead> wrapLeadList {get; set;} public List<Lead> accs {get; set;} public void ConvertedLeadList(){ accs = [SELECT Id, Name, ConvertedAccountId, ConvertedContactId, ConvertedOpportunityId, Status FROM Lead WHERE IsConverted=true]; // System.debug(accs); } public AAAExisting(){ if(wrapLeadList == null) { wrapLeadList = new List<wrapLead>(); for(Lead a: [select Id, Name, Company, Email, Phone, Status FROM Lead WHERE IsConverted=false]) { // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList wrapLeadList .add(new wrapLead(a)); // System.debug(wrapLeadList); } } } Public void autoLeadConversion(List<Lead> autoLeadConversions) { // List<Lead> autoLeadConversions= new List <Lead>(); for(Lead lead: autoLeadConversions){ if (lead.isConverted == false) { //to prevent recursion Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(lead.Id); String oppName = lead.LastName; lc.setOpportunityName(oppName); LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1]; lc.setConvertedStatus(convertStatus.MasterLabel); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); } } } public void processSelected() { for(wrapLead wrapAccountObj : wrapLeadList ) { if(wrapAccountObj.selected == true) { Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(wrapAccountObj.acc.Id); lc.setopportunityname(wrapAccountObj.acc.Company); LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1]; lc.setConvertedStatus(convertStatus.MasterLabel); Database.LeadConvertResult lcr = Database.convertLead(lc); } } } // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value public class wrapLead{ public Lead acc {get; set;} public Boolean selected {get; set;} //This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false public wrapLead(Lead a) { acc = a; selected = false; System.debug('convertStatus'+ acc); } } }
I have gone through your problem. Please try the below code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
All Answers
The below link gives a description of writing a test class for an apex unit class.
>> https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
Can you please check this once and in case if this was helpful for your implementation can you please choose this as the best answer so that it can be used by others in the future.
Regards,
Anutej
I have gone through your problem. Please try the below code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora