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
Sol2012Sol2012 

Update owner in *custom* object (using a trigger)

Hello,

I have created a trigger that allows me to assign the proper owner to my opportunities.

I am willing to do the same on a *custom* object, but I cannot use the OwnerId: the (standard) API does not provide this field.

This is very rare for two reasons:

 

  1. The "OwnerId" field can be assigned by external tools such as "Apex Loader" and "Apatar connector".
  2. I can see all the other standard fields in my custom object, using the following code:
Map<String, Schema.SObjectField> m = Schema.SObjectType.MyCustomObject__c.fields.getMap();

 

 

 

Am I missing something here? Is there any workaround?


Thanks and regards

Best Answer chosen by Admin (Salesforce Developers) 
Prajapati.LakhanPrajapati.Lakhan

Is there any master detail relationship between your custom object, because in that case detail object do not have ownerId field.

Its implicit owner will be parent record's owner .

 

 

 

Thanks,

Lakhan

All Answers

Prajapati.LakhanPrajapati.Lakhan

Is there any master detail relationship between your custom object, because in that case detail object do not have ownerId field.

Its implicit owner will be parent record's owner .

 

 

 

Thanks,

Lakhan

This was selected as the best answer
Sol2012Sol2012

 

    Thank you Lakhan,

 

    I figured out what had happened a couple of hours ago: I was using Apex Data Loader and Apatar against production, whereas I was testing a trigger in a Sandbox environment.

 

    Exactly as you are pointing here, Sandbox environment had Master-Detail relationships, so those fields were hidden.

 

    Thanks for your help anyway, and have a great day!