You need to sign in to do that
Don't have an account?

HELP!! Writing a test class for a lead trigger that autoconverts a lead into a person account when it comes in through a weblead
I'm very new to apex and programming, and I've come up with the following trigger, but need a test class in order for it to be deployed. What we essentially want to do is autoconvert the lead into a person account when the company field is blank, (coming in via an external webform).
Here's the trigger:
any help would be MUCH appreciated!! :)
Here's the trigger:
Trigger AutoConverter on Lead (after insert) { LeadStatus convertStatus = [ select MasterLabel from LeadStatus where IsConverted = true limit 1 ]; List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>(); for (Lead lead: Trigger.new) { if (!lead.isConverted) { Database.LeadConvert lc = new Database.LeadConvert(); String oppName = lead.Name; lc.setLeadId(lead.Id); lc.setOpportunityName(oppName); lc.setConvertedStatus(convertStatus.MasterLabel); leadConverts.add(lc); } } if (!leadConverts.isEmpty()) { List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts); } }
any help would be MUCH appreciated!! :)
Please try below,
Best regards
Sampath
All Answers
Please try below,
Best regards
Sampath
Hi Sampath, many thanks for that!
I deployed the test class and the trigger into production but the following error came up:
How do I resolve this?? Would I have to write a HTTP callout??
Many Thanks!! :)
Natasha
Below link is related to the same issue I think.
https://developer.salesforce.com/forums/?id=9060G000000UZraQAG (https://developer.salesforce.com/forums/?id=9060G000000UZraQAG)
Best Regards
Sampath