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

Make contact owner same as account owner.

Hi, We have a requirement like whenever user creates a new contact, the contact owner should be same as the account owner of the contact. For this we have written the below apex trigger:

trigger ChangeOwner on Contact (before insert)

{        Contact[] cons =;        for(Contact c:cons)    {

               String ownerId = [select ownerId from Account where Id =: c.accountId].ownerId;                 System.debug('Query Success-->'+ownerId);             c.ownerId = ownerId;              System.debug('Owner set Success-->'+c.ownerId);



This is working fine for System Administrator
But when a standard user tries to create a contact, it shows the error message as
"Insufficient Privileges
 You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary."
 Can anybody please help me out?
 Thanks and Regards,

Systen admin and who has modify all data permission can do this. but practically it is not good to  give modify all dat aprmission to standard users.

But in your case, user is going to update his/her own contact records. so probably the have rights to do it as they have edit permission on their own records.

If you trigger this 'after insert' make sense. I am not sure, you may try this.