You need to sign in to do that
Don't have an account?
Assistance with Lead autoconvert Trigger
Hi there,
I'm attempting to cobble together some code for a lead convert trigger that will (after update, after insert) ensure the resulting Account's name is the Last Name plus the last 4 digits of the phone number and I'm a little stuck. For example, if you were converting a lead named John Smith and his phone number was 123-456-7890, the resulting account would be called "Smith-7890". The piece for the trigger to autoconvert works fine, but the portion updating the account is giving me from trouble. Any advice would be appreciated!
I'm attempting to cobble together some code for a lead convert trigger that will (after update, after insert) ensure the resulting Account's name is the Last Name plus the last 4 digits of the phone number and I'm a little stuck. For example, if you were converting a lead named John Smith and his phone number was 123-456-7890, the resulting account would be called "Smith-7890". The piece for the trigger to autoconvert works fine, but the portion updating the account is giving me from trouble. Any advice would be appreciated!
trigger LeadConvert on Lead (after insert,after update) { //Bulkified List<String> LeadNames = new List<String>{}; for(Lead myLead: Trigger.new){ if((myLead.isconverted==false) && (myLead.Status == 'Scheduled Appointment')) { Database.LeadConvert lc = new database.LeadConvert(); lc.setLeadId(myLead.Id); lc.convertedStatus = 'Scheduled Appointment'; //Database.ConvertLead(lc,true); lc.setDoNotCreateOpportunity(true); Database.LeadConvertResult lcr = Database.convertLead(lc); System.assert(lcr.isSuccess()); } } List <Account> account = [SELECT acc.Id, acc.Description FROM Account acc WHERE acc.Id = :Trigger.new.ConvertedAccountId]; for (Account acc: account) { acc.Name = Trigger.new.LastName + Trigger.new.RIGHT(Phone, 4); update acc; } }
I have updated your trigger there were some missing syntax.Try the below code should work now.
All Answers
I have updated your trigger there were some missing syntax.Try the below code should work now.
Follow up to this. Is there a way to avoid "null pointer exception" errors when they don't fill in a phone number with this trigger?
Thanks,
Travis
replace these lines
with this one