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
KellymtKellymt 

How to find the layout assigned to a particular user from Apex?

Does anybody know how can I find the layout assigned to a particular user from Apex?
I know that the Metadata API will give me that information:   
 MetadataService.Profile profile = (MetadataService.Profile)service.readMetadata('Profile', new String[] { profileName }).getRecords()[0];
           for(MetadataService.ProfileLayoutAssignment layoutAssignment : profile.layoutAssignments) {
               if(layoutAssignment.layout.startsWith('Account')) {
                   accountLayoutName = layoutAssignment.layout;
                   break;         
               }
           }
but the metadata API is not available from within Apex and using the MetadataService provided by FinancialForce.com (great job guys) seems like an overkill to me.
Also does anybody know if the MetadataAPI counts towards your API call limits?

Thanks,
Kzmp
Christopher ShadeChristopher Shade
Kzmp,

You Apex supports SOQL queries.  You could try something like this:

SELECT ProfileId, Username, Profile.Name
FROM User
WHERE ID = '005o0000000FuCt'

Chris
 
KellymtKellymt
Hi Chris,
Thank you for your response. 
I am able to query the profile but I am not able to find out how to find the layout assignments via SOQL. Do you have an idea how to do that?

Kzmp