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
REKREK 

regarding apex trigger

writing trigger to update a field when a record is inserted in open activities and activity history.
Pradeep_NavatarPradeep_Navatar

Try out the sample trigger given below :  

 

                                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)

                                                {

                                                                system.debug('############3');

                                                                if (leadMap.containsKey(tsk.Whoid))

                                                                {

                                                                                Lead l = leadMap.get(tsk.Whoid);

                                                                                system.debug('>>>>>>>>>>' +l.id);  

                                                                                tsk.Description = tsk.Description + '\n'+ l.Company + '\n' + l.Street +'\n'+

                                                                                l.City + ', ' + l.State + ' ' + l.PostalCode + '\n' +  l.Phone;

                                                                                system.debug('>>>>>>>>>>' + tsk.Description);

 

                                                                }  

                                                }

                                }    

 

Hope this helps.