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
Alex23Alex23 

Could I have help on a Apex trigger to auto populate lead address in task section.

Could I have help on a Apex trigger to auto populate lead address in task section. thank you!!! Alex C.

 

 

krishnagkrishnag

what is your scenario. It would be great if you can clearly mention that,

Alex23Alex23

In my "leads" tab I input all the address, phone #, name.  Then when I go down and make a " new task" for that "lead" in the task section the name , phone #, and e-mail are already populated I would like to have the address populate there as well.

Thank you for Helping

 

Alex

jkucerajkucera

Yes - you'd want a before insert task trigger that adds the address either to the beginning or the end of the Description

Alex23Alex23

Thanks i still am trying to understand it. Are there any books that could help me I still don't understand on how to create a trigger to make this action happen. thank you for your help 

jkucerajkucera

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex

 

Here's my quick bad syntx version so you have a sense for what it might looks like:

 

trigger addAddres on task (before insert){

 Set<id> leadIds=new Set<Id>();

 for (Task t: trigger.new){

    if(t.WhoId!=Null){

      if(t.WhoId.startsWith('00Q')){//All lead Id's start with 00Q

        leadIds.add(t.WhoId);

      }

  }

  }

 

  List<Lead> leads=[Select State, PostalCode, Id FROM Lead WHERE Id IN:leadIds];

  For (Task t2:trigger.new){

    for(Lead l:leads){//note this coudl be more efficient, but i left as is for ease of reading

      if (l.Id==t2.WhoId){

         t2.Description+=l.State+l.PostalCode;

     }

  }

}

Alex23Alex23

Thank you very much now I will now knowledge myself on where to place this and learn a new language.

 

thank you!!!

Alex

C