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
JGFJGF 

SOQL Automated Process by its name changes with the users profile locale

Hello everyone,

I have a very peculiar situation. For the creation of a particular record I need the Automated Process User Id, up to now this is the way I obtained it.
 
[SELECT Id FROM User Where Name = 'Automated Process']
Everything was correct until a new user arrived that set his profile Locale to Chinese.

Now this previous Query does not work as the name for the "Automated Process" user has changed to "Process Automated", giving 0 results for this query.

Is there a proper way to retrieve this "Automated Process" user without having the name issue because the Users locale?
Best Answer chosen by JGF
JGFJGF
Hello everyone,

The answer given by Siddharth Mani gave me the idea to query the user by his alias, that it always be autoproc regardless of the Locale or language configuration.With this the org ID will not get in the way.

[SELECT Id FROM User Where alias = 'autoproc']
 

All Answers

Siddharth ManiSiddharth Mani
Try this - get your organization id from navigating to Company Information in Setup. Its the field with label "Salesforce.com Organization ID". Once you have the id, convert it into 18 digit format and try this query:

[SELECT Id FROM User Where UserName = 'autoproc@00h2b000005hunoeao']
In the above query, the Id parameter i.e. "00h2b000005hunoeao" is the 18 digit org id which you obtained above.

If you want a more generic version where you dont want to use the organization id then you can try this:
SELECT Id FROM User Where username like '%autoproc@%'

The above query obviously asumes that you do not have another user in your org with 'autoproc@' in the username.
AnudeepAnudeep (Salesforce Developers) 
Hi JGF, 

You have to Use toLabel(fields) to translate SOQL query results into the user’s language.

Please follow  https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_tolabel.htm

Let me know if this is helpful by marking the answer as solved so that it can help others in the future

Anudeep
JGFJGF
Hello everyone,

The answer given by Siddharth Mani gave me the idea to query the user by his alias, that it always be autoproc regardless of the Locale or language configuration.With this the org ID will not get in the way.

[SELECT Id FROM User Where alias = 'autoproc']
 
This was selected as the best answer