4

I'm using the jsforce node package and I've tried the following:

conn.metadata.retrieve(
    {
        apiVersion: '38.0',
        unpackaged: {
            types: [
                {
                    members: ['Contact'],
                    name: 'Layout'
                }
            ]
        }
    }
).stream().pipe(fs.createWriteStream('contact.zip'));

Which results in the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Contact</members>
        <name>Layout</name>
    </types>
    <version>38.0</version>
</Package>

I'm not sure where to retrieve all layouts from. I can do it via the describeLayouts() endpoint, but that seems to exclude the actual layout names which I definitely need.

I referenced this question and turned to the metadata file-based API calls which is shown above. I also did name: 'CustomObject' but it wasn't part of that response either. Any ideas?

Edit with REST API response: enter image description here

8

Use the Tooling API to query for the layouts:

SELECT FullName FROM Layout WHERE TableEnumOrId = 'Contact'

You can read more about the Tooling API REST Calls.

Here's the raw endpoint you would use:

/services/data/v38.0/tooling/query?q=SELECT+FullName+FROM+Layout+WHERE+TableEnumOrId=%27Contact%27

Example Output:

{
  "size" : 1,
  "totalSize" : 1,
  "done" : true,
  "queryLocator" : null,
  "entityTypeName" : "Layout",
  "records" : [ {
    "attributes" : {
      "type" : "Layout",
      "url" : "/services/data/v38.0/tooling/sobjects/Layout/00h50000000yfyCAAQ"
    },
    "FullName" : "Contact-Magical Happy Land"
  } ]
}
7
  • Yeah I was trying to give that a shot, but didn't see the actual name of the layout coming back, just the record type name – Matt Altepeter Jan 13 '17 at 20:14
  • see my edit with the response from that endpoint. The names in this section are the record type names and I didn't see anything in the Layouts section to indicate a layout name – Matt Altepeter Jan 13 '17 at 20:22
  • @MattAltepeter Found an answer in the tooling API. Take a peek. – sfdcfox Jan 13 '17 at 20:48
  • 3
    One caveat for future readers: selecting the FullName attribute can only be done when the result will return exactly one layout. Use Name instead to get all the layout names – Matt Altepeter Jan 20 '17 at 18:10
  • 1
    @doga Yes, TableEnumOrId needs to be the Custom Object Id for custom objects. Use a query on CustomObject to find the Id that you need to use. – sfdcfox Sep 17 '18 at 8:15

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.