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
Kumbresh KKumbresh K 

How to enable the record types for the automated user profile through apex code?

We have implemented a platform event trigger (gives additional governor limit and executes synchronously) in our product to overcome the SOQL 101 limit issue. As we know that, the platform events executed as an automated user.

In this implementation, we are updating a custom object as well as setting up the record types. Currently, to enable the record types for the automated user profile we are doing URL hacking using the system Administrator profile manually. This is the workaround we found in the development forum. Please refer below.
https://salesforce.stackexchange.com/questions/210710/automated-process-user-profile-permissions
https://goravseth.com/giving-automated-process-user-access-to-apex-class

The problem is, we have around 50+ clients and this is a pretty complicated config and needs to do in all 50+ clients on every release or package upgrade.

Can it be done with the script if yes what is the solution?
AnudeepAnudeep (Salesforce Developers) 
I think it cannot be achieved through apex because we cannot create record type in a class because this object does not support DML 

As per this documentation

sObjects That Do Not Support DML Operations in Apex

AccountTerritoryAssignmentRule
AccountTerritoryAssignmentRuleItem
ApexComponent
ApexPage
BusinessHours
BusinessProcess
CategoryNode
CurrencyType
DatedConversionRate
NetworkMember (allows update only)
ProcessInstance
Profile
RecordType
SelfServiceUser
StaticResource
Territory2
UserAccountTeamMember
UserPreference
UserTerritory
WebLink

Let me know if it helps
Kumbresh KKumbresh K
Hi Anudeep,

I don't want to create a record type in Apex. I want to enable the record type permission on profile level for Automated User

I got the solution and in a recent release Salesforce has given option to "Configure the User and Batch Size for Your Platform Event Trigger" and this solved my problem

For reference:
https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_trigger_config.htm
https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_platformeventsubscriberconfig.htm

Thanks,
Kumbresh