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

LeadConvert on Lead Status Change to Qualified
I'm starting to get a little dangerous with APEX. :smileyhappy:
My sandbox went down for mainteniance as I was getting ready to test this a second time - it didn;' work the first time. I think I might be misunderstanding how trigger.old and new are suppsed to work. Will this code automatically convert a lead when the status is changed to qualified?
Also - my test class only gets 76% converage. To help get a better understanding, what would I need to add to get to 100%?
trigger LeadConvert on Lead (after update) { // no bulk processing; will only run from the UI and Lead Status must be changed to qualified if (Trigger.new.size() == 1) { if (Trigger.old[0].isConverted == false) { if (Trigger.new[0].isConverted == false && Trigger.new[0].Status == 'Qualified') { } } } }
Test Class:
public class LeadConvert { static testMethod void LeadConvert() { //create a lead with qualified status lead l1 = new lead(); l1.status = 'Qualified'; l1.lastname = 'Joe'; l1.firstname = 'Smith'; l1.company = 'Company ABC'; l1.isConverted = False ; insert l1; string holder = l1.id; //create lead that does not match criteria Lead L2 = new lead(); L2.Status = 'Open'; L2.lastname = 'Jane'; L2.firstname = 'Smith'; L2.company = 'Company DEF'; L2.isConverted = False; insert L2; string holder2 = L2.id; //Update L2.Status = 'Qualified'; update L2; } }
Tried this too - no dice. I thought this would work for sure too!!
You would need to call Lead.Convert() (or whatever it's callaed) in your inner if statement.
You're right - i forgot to paste the last part. I got it working - the code is here:
Now on this test class - any idea how I can get this moved from 81% coverage to 100% coverage?
At a quick glance you should have 100% coverage with that test class, but I may be missing something.
Start by rerunning the test method and then look at exactly which rows are not covered. This is available when you click the "81%" part in the test output window - it pops up your class with red lines where it's not covered.
Thanks for the reference - I didn't know I could just click on that number to visually see the coverage - that helps!
Now the last piece I'm struggling with is how to write the syntax so that the system checks to see if there is already a matching AccountID. If so, then populate any blank fields and do not overwrite anything else (which I think is the default . On the contact object, I want it to look at first name, last name and phone for the match.