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
Bryan Revelant 7Bryan Revelant 7 

Record Type assignment based on user or group

Hello, 

If the user is assigned to a 1 record type but there are two on the object how can you program this on save?

I have a Visualforce page that saves records. Upon save the record type is null. I controll record types with visibility. I have done some research however I am comming up a bit short. The permission sets sets the record type. The below methods states that the current users does not require access :( I want to set the record type on save to whatever the permssion set says they have. 

getRecordTypeInfos()
Returns a list of the record types supported by this object. The current user is not required to have access to a record type to see it in this list.
getRecordTypeInfosById()
Returns a map that matches record IDs to their associated record types. The current user is not required to have access to a record type to see it in this map.
getRecordTypeInfosByName()
Returns a map that matches record labels to their associated record type. The current user is not required to have access to a record type to see it in this map.
Vinit_KumarVinit_Kumar
You need to set the RecordTypeId while saving the record in your Controller,something like below :-

//Inserting an Account record
Account acc = new Account(Name='ABC',RecordTypId='<Id of the RecordType you want to provide>');
insert acc;

If this helps,please mark it as best answer to help others.
Bryan Revelant 7Bryan Revelant 7
I am assigning record types by permission sets, with that being said, how do i know which users has which permission set assisnged. I cant really do a case statement correct?
Vinit_KumarVinit_Kumar
You should query on PermissionsetAssignment to know which user is assigned to which permission set,something like below :-

SELECT Id, PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId = '<Id of User>'

PermissionSetId = Id of the PermissionSet 
AssigneeId  =  Id of User

Go through the below link to learn more about this object :-

https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_permissionsetassignment.htm

If this helps,please mark it as best answer to help others.