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
Janusz Gorycki 7Janusz Gorycki 7 

Problem using metadata API to update SearchLayout buttons

Hi all,

I am trying to add custom buttons to search layouts using metadata API. Here is the java code:
ReadResult result = connection.readMetadata("CustomObject", new String[]{objectName});
Metadata[] records = result.getRecords();
CustomObject customObject = (CustomObject) records[0];
SearchLayouts layouts = customObject.getSearchLayouts();
ArrayList<String> buttons = Lists.newArrayList(layouts.getListViewButtons());
buttons.add(BUTTON_NAME);
layouts.setListViewButtons(buttons.toArray(new String[buttons.size()]));
customObject.setSearchLayouts(layouts);
connection.updateMetadata(new Metadata[]{customObject});

BUTTON_NAME is the name of the WebLink which has been created previously.
This works, but only when I have never accessed any of the list views of the object for which I want to add the button (I have a fresh dev instance set up, so this is still possible). 

If the list view has ever been visited, the button does not show up (see screenshot).
User-added image
However, the button does show up in the setup for "Search Layouts" for the object in question - as if it has been added to the layout. Plus querying the custom object reports the button as present in the layout also. And when I click the "Save" button in on that page (without modifying anything), the button suddenly appears in the list view!
User-added image
It is as if salesforce is doing some additional work when I click "Save" in addition to what the metadata API does. Plus the same additional work is apparently performed when the list view is accessed for the first time.

This is not a browser caching issue (I have tried on may browsers simultaneously).
This has also previously been reported by at least two people on some forums:

http://salesforce.stackexchange.com/questions/59784/metadata-api-searchlayouts-not-showing-updates
https://github.com/financialforcedev/apex-mdapi/issues/55


Does anybody know what is going on? And how I could fix this?
mintotsai@dev.jasminemintotsai@dev.jasmine
I am running into the same issue. Any new information?