function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Carl BussemaCarl Bussema 

Metadata API retrieves incomplete data for Search Layout with Custom Fields

This has been reported (https://developer.salesforce.com/forums/?id=906F0000000fyRsIAI) before (https://salesforce.stackexchange.com/questions/187113/how-to-deploy-search-layout-containing-custom-fields) in different ways, I expect these two reports are symptoms of the same problem, namely that search layouts do not retrieve and/or deploy correctly using metadata API when they include custom fields and/or buttons.

Reproduce:

  1. Add a custom field to Product2 (enable FLS for all profiles to rule that out).
  2. Customize the Price Book Entry default search layout to include that new field
  3. Retrieve the Price Book Entry object using Metadata API
  4. Observe the search layout contains a nil field instead of the custom field.
Here's an example from our org, with 2 custom fields. 
 
<searchLayouts>
   <searchResultsAdditionalFields>PRODUCT.NAME</searchResultsAdditionalFields>
<searchResultsAdditionalFields>PRODUCT.CUSTOMER_PRODUCT_ID</searchResultsAdditionalFields>
        <searchResultsAdditionalFields xsi:nil="true"/>
     <searchResultsAdditionalFields>PRODUCT2.FAMILY_ENUM</searchResultsAdditionalFields>
        <searchResultsAdditionalFields xsi:nil="true"/>
    </searchLayouts>
This makes it impossible to deploy the search layout customization, and it must be recreated by hand in each environment.
 
Carl BussemaCarl Bussema
I did a little more digging, and it may be that this only effects special layouts like PricebookEntry, where all the fields are cross-object. I tested with a custom object and even a cross-object formula works fine, and a standard object's custom field is fine too, it just happens on PricebookEntry.
MUSTAPHA ELMADIMUSTAPHA ELMADI
Hello Carl,

Did you find a way to deploy for PriceBookEntry too ?

Thanks
Carl BussemaCarl Bussema
We had admins hand-create/modify the layout in each environment. It was the only workaround we could find.
MUSTAPHA ELMADIMUSTAPHA ELMADI
The bug apparently was fixed behind the scene by Salesforce.
I succeded to deploy it.