Is there is any way possible to extract the list of fields used on specific page layout?
I know it is possible from page layout, but need the way if this can be extracted from some other way.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityIs there is any way possible to extract the list of fields used on specific page layout?
I know it is possible from page layout, but need the way if this can be extracted from some other way.
It is also possible using a SOAP call. Take a look at the describeLayout doc for specifics.
You can then call the code from apex. Here I'm using a xml body, but you can try it other ways
String endpoint = System.URL.getSalesforceBaseURL().toExternalForm()+'/services/Soap/u/36.0';
String body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">'+
'<soapenv:Header>'+
'<urn:SessionHeader>'+
'<urn:sessionId>'+UserInfo.getSessionId()+'</urn:sessionId>'+
'</urn:SessionHeader>'+
'</soapenv:Header>'+
'<soapenv:Body>'+
'<urn:describeLayout>'+
'<urn:sObjectType>'+record.Id.getSobjectType()+'</urn:sObjectType>'+
'<urn:layoutName>'+someNameVariable+'</urn:layoutName>'+
'</urn:describeLayout>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', 'describeLayout');
req.setBody(body);
Dom.Document doc = h.send(req).getBodyDocument();
dom.XmlNode envelope = doc.getRootElement();
String envelopeNamespace = 'http://schemas.xmlsoap.org/soap/envelope/';
String sfNamespace = 'urn:partner.soap.sforce.com';
//iterate through xml to find desired information
You'd probably want use an aplication like Postman or SoapUI to test the call beforehand and know how to parse it
This is possible using Force.com IDE.
You will want to open up the IDE and then click File > Force.com > Project Properties.
And then when the window opens up Make sure that Project Contents
is selected on the left and then scroll all the way down to Page Layout
and select the layout in question. You will be able to export an XML file of all fields for that specific page layout.
Please see this post for some more details on this process. If you unfamiliar with force.com IDE please see the overview page here.
Hope this helps you.