3

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.

  • I didn't add it as an aswer, because I have little knowledge about it, but you can also take a look at the Metadata API – Fernando Gavinho Jul 27 '16 at 16:14
3

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

  • Can you please add some content from the link? Think about what this post would look like if your link broke. It should be able to stand alone to at least some extent. – Adrian Larson Jul 27 '16 at 16:22
2

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.

  • Can you please add some content from the links? Think about what this post would look like if all the links broke. It should be able to stand alone to at least some extent. – Adrian Larson Jul 27 '16 at 16:21
  • @AdrianLarson that look better? I just didn't want to copy the other post seeing as it is the correct answer, but I understand why I should have added some more than just the links. – cmmoutes13 Jul 27 '16 at 16:26

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.