You need to sign in to do that
Don't have an account?
fgwarb_dev
Apex - How do you determine the default record type for a user?
I'm looking for something like this:
Schema.CurrentUser.Opportunity.getDefaultRecordType();
Thanks!
Have a look at this page from the docs:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject_describe.htm
At the end there's a section on recordTypeInfos. I think you can use the isDefaultRecordTypeMapping method. Its not 100% as the docs don't mention the current user, but I seem to recall I've read somewhere that this is the mechanism.
We're running in system mode, so I need some way to explictly associate the recordtype to the user. Like on the Profile...
I haven't found any way to get at that information programmatically I'm afraid.
Mind you, I don't think that running in system mode should be a problem as long as your code is being executed as the logged in user (i.e. not scheduled apex or incoming web services).
For default you could use "Master".The default record type is defined at the profile level. So, whichever user is describing the object will see their own defaultRecordTypeMapping defined for their Profile.
You could get recordId by developer name, see relase info https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_apex_developer_name.htm
The if two different user with diferent profile run same code, the will see their own default record respectively.