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
Salesforce Dev in TrainingSalesforce Dev in Training 

Owner Field Default

Hello, I have a custom object titled "Interview Results". I have a lookup field titled "Owner". This field should default a value of whomever is logged into the org. For example, it's a lookup to "User", so the field should be the User logged in.

Is it possible to write a before insert trigger to populate this field?

SalesFORCE_enFORCErSalesFORCE_enFORCEr
You cannot set a default value to a lookup field before saving the record. Also, the creator or logged in user will be the owner of the record so I am not sure why do you wnat to default it.
Salesforce Dev in TrainingSalesforce Dev in Training
That's the problem... the logged in User is NOT being set in this field. They're having to manually look up their name which is not ideal.
Salesforce Dev in TrainingSalesforce Dev in Training

User-added image

The field is null when I click a new "Interview Results" record.

SalesFORCE_enFORCErSalesFORCE_enFORCEr
Is this the standard Owner field or have you created a custom one?
Salesforce Dev in TrainingSalesforce Dev in Training
It's a custom field.
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Ok in that case, you can just create a process builder to update the owner field with $User.Id 
Salesforce Dev in TrainingSalesforce Dev in Training
I'm attempting this, but that's where I am having difficulties. Perhaps I am missing something.
swati_sehrawatswati_sehrawat
You have a standard field on every salesforce object, "CreatedBy" which automatically saves the id of logged in user who has created the record. Why you are not using that and creating a custom field for the same.