I have a requirement where i need to get page layout name dynamically in apex on the basis of record type(page layout associated with it) selected by user. I am overriding account's new button in lightning,it asks me to select the record type and then it redirects me to my custom component.How to get the record type name(or page layout name) selected by user?


I finally found the solution for this issue,I used Named Credential to resolve this issue. To create Named Credentials i used this link, https://rajvakati.com/2018/01/28/salesforce-ui-api-lightning-examples/

used this link, Getting Page Layout associated to a Profile/RecordType

to set tooling API,the change which i made was ,i replaced

'/services/data/v41.0/tooling/query?q='+ (query.replace(' ', '+')) in following method

static String toolingAPISOQL( String query) {
String baseURL = URL.getSalesforceBaseUrl().toExternalForm();
return restGet( baseURL +'/services/data/v41.0/tooling/query?q='+ (query.replace(' ', '+')),'GET', UserInfo.getSessionId() );} 


static String toolingAPISOQL( String query) {
    String baseURL = URL.getSalesforceBaseUrl().toExternalForm();
    return restGet('callout:PageLayout/services/data/v41.0/tooling/query?q='+ (query.replace(' ', '+'))

in this callout is fixed name used for named credential and PageLayout is the name of the named credential which i created

| improve this answer | |

You can use tooling API to get required information.

SELECT Layout.Name, Layout.TableEnumOrId, ProfileId, Profile.Name, RecordTypeId FROM ProfileLayout where recordtypeid='012f4000001DjwsAAC'

Check Tooling API Guide to get more information on this.

| improve this answer | |
  • This was the first thing which i implemented,but i have to call this API from lightning and it doesn't let me use session ID(gives error INVALID_SESSION_ID),there was an alternate solution by using VF,but it will be used in Appexchange app so can't use.If you have any other suggestions,please let me know. – NEELESH Jun 10 '19 at 20:23
  • have you checked this link salesforce.stackexchange.com/questions/32683/… – Dhanik Lal Sahni Jun 11 '19 at 13:37
  • Yes,this was the first solution which i implemented but no success – NEELESH Jun 12 '19 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.