function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RobBirdRobBird 

Lead information on a Task

Good day. I am not sure if this question should be here on on the Formulas and Validation Rules board, so I am posting it in both places.

 

We have a need to take Lead information (phone number, State, etc.) and have that info appear on the Task when a Task is created for that Lead. I have been struggling with this for a while and it's driving me crazy. I would seriously give someone some $ if they could give me a way to do it.

 

Thank you!

 

R

 

Best Answer chosen by Admin (Salesforce Developers) 
kbromerkbromer

I hope to be, you can buy me a beer at the Expo ;)

 

Definitely mark this question as answered too, if you don't mind!

 

 

All Answers

kbromerkbromer

Here's a trigger on Task before insert that would do it:

 

trigger CopyLeadInformation on Task (before insert) {

list<id> WhoIds = new list<id>();
for (Task t : trigger.new)
    WhoIds.add(t.WhoId);

list<Lead> leadList = [select id,Company,Street,State,City,Phone,PostalCode from Lead where id in :WhoIds];
map<id, Lead> leadMap = new map<id, Lead>();

for(Lead l : leadList)
    leadMap.put(l.id, l);
   
for (Task tsk : trigger.new){
    if (leadMap.containsKey(tsk.Whoid)){
        Lead l = leadMap.get(tsk.Whoid);
            
        tsk.Description = tsk.Description + '\n'+ l.Company + '\n' + l.Street +'\n'+
        l.City + ', ' + l.State + ' ' + l.PostalCode + '\n' +  l.Phone;
        }   
    }
}

 

 

RobBirdRobBird

So with this formula, it will take all of the info we are requesting (select id,Company,Street,State,City,Phone,PostalCode) and put it into the comments section (tsk.Description = tsk.Description) of the Task, correct?

 

If I wanted to link a specific field on the Lead to a specific field on the Task, what would I add?

 

Thank you so much for all your help!

 

R

kbromerkbromer

Yes, that's correct.

 

I'm not sure I understand what you mean by 'link a specific field'. Could you clarify?

RobBirdRobBird

For example, if I wanted to take the phone number from the Lead, and have that number put into a field on the Task called phone number, what would I need to add?

 

Thank you for your time!

 

Rob

kbromerkbromer

You'd change this line:

 

 tsk.Description = tsk.Description + '\n'+ l.Company + '\n' + l.Street +'\n'+
l.City + ', ' + l.State + ' ' + l.PostalCode + '\n' + l.Phone;

//Replace with:

tsk.Phone = l.Phone; //Put the lead value into the phone field
tsk.CompanyName__c = l.Company //Put lead company name in custom task field CompanyName



RobBirdRobBird

I think I see how to do that. I will give it a try. If you'll be at Dreamforce, let me know. I owe you something for this for sure.

 

Thank you so much!!!

kbromerkbromer

I hope to be, you can buy me a beer at the Expo ;)

 

Definitely mark this question as answered too, if you don't mind!

 

 

This was selected as the best answer