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
VineetaVineeta 

Please help me in writing After trigger

Hi Friends
I want to write a trigger on contact for "After Insert" and "After Update" to get email Id and ContactOwner and insert into Contact Email field.
I have written this code
 
trigger MyContactTrigger on Contact (after insert , after update) {
if(Trigger.isAfter)
{
 if((Trigger.isInsert) || (Trigger.isUpdate))
 {
  for (Contact c :trigger.new)
  {
                    Contact[] OwnerId = [Select OwnerId from Contact where Id in :Trigger.new];
            for(Integer i=0;i<OwnerId.length;i++){
 c.Email =[Select E_mail from User where Id =OwnerId[0]];}
                    }
          }
}
}
 
I have found Compile Error: unexpected token:.
 
Please let me know how to write this trigger.
 
Pseudocode Is like this:
 
get OwnerId from Contact
Get Email from User where Id=c.OwnerId
c.email =Email
 
Thanks
Vineeta
 
thorsten_dthorsten_d
Hi Vineeta,

try OwnerId.size() instead of OwnerId.length

it's not tested, just an idea.

/thorsten