5

If I know layout name I can read what layout contains using following Metadata. At the same time if somebody changes Layout name this code won't work at all. Could you please advise if I can get the name of layout currently assigned to user for the object?

List<Metadata.Metadata> mm= Metadata.Operations.retrieve(Metadata.MetadataType.Layout , new List<String> {'Account-Account Preview Layout'});
        ILayoutI = (Metadata.Layout) mm.get(0);

2 Answers 2

0

I 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() );} 

with

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

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

0

Try this to get the current layout. It retrieves the layout assigned to the user for a specific object and optionally based on the record type.

public String getLayoutName(Id recordTypeId) {
  Record record = new Account(); // Replace with your object type
  if (recordTypeId != null) {
    record.RecordTypeId = recordTypeId;
  }
  Schema.SObjectType objectType = record.getSObjectType();
  RecordTypeInfo recordTypeInfo = record.getRecordTypeInfosByName().values().iterator().next(); // Assuming a single record type

  PageLayout layout = record.getRecordCreateDefaults(objectType, recordTypeInfo);
  return layout != null ? layout.getName() : null;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .