+ Start a Discussion
Raji KannanRaji Kannan 

Can we run an apex trigger in a user context to create a record so that the created by Field is always a single user?

Hello Group Members,

I just have a qauestion about apex trigger which is used to create a record. This trirgger currently sets the created by user to current user who has doen the transaction. Is there any way to make sure that I set the user to run the apex trigger in a saingle user context so that the record created by field is always same user irrespective of who did the transaction?
Niraj Kr SinghNiraj Kr Singh
Hi Raji Kannan,

It can not be possible directly.
1. Either you can not give create permission to all user for that specific object except to an user to whom you want.
2. Check with this post:
   https://salesforce.stackexchange.com/questions/128426/set-a-specific-value-for-created-by-field-of-a-custom-objects-all-records-in-sa
https://success.salesforce.com/answers?id=9063A000000svmMQAQ


Please let me know if it helps you!