I followed instructions given in https://github.com/financialforcedev/apex-mdapi to create list views in my dev org. I am trying to create List View for Accounts.

I am able to create simple list without any issues. But I when I tried to add a filter and list of columns, I am getting FIELD_INTEGRITY_EXCEPTION error

I appreciate if any one can help narrow down the issue

Here is the code I am using

        MetadataService.MetadataPort service =  MetadataService.createService();
        MetadataService.ListView listView = new MetadataService.ListView();
        MetadataService.ListViewFilter filter = new MetadataService.ListViewFilter();
        List<MetadataService.ListViewFilter> filterListToAdd = new List<MetadataService.ListViewFilter>();

        listView.fullName = 'Account.' + newlistview;
        listView.label = newlistview;
        filter.field = 'Account.ACCOUNT NAME';
        filter.operation = 'equals';
        filter.value = 'Acme';

        System.debug('ListViewController::createnew creating ' + listView.fullName);

        listView.filters = filterListToAdd;
        listView.filterScope = 'Everything';
        listView.columns = new List<String> { 'Account.Account Name','Account.OwnerId','Account.Type'};
        listView.columns = new List<String> { 'Account.Name'};

        List<MetadataService.SaveResult> results = service.createMetadata(new MetadataService.Metadata[] { listView });

1 Answer 1


Field names do not have spaces in them; they are always alphanumeric with underscores. Furthermore, the metadata API uses the underlying database names for standard fields. There's no clear documentation for existing fields, so in order to be able to create list views, you'll typically have had to at least created one manually to see what it is supposed to look like.

In your case, the field name is ACCOUNT.NAME.

filter.field = 'ACCOUNT.NAME';

Here's an example XML from a basic list view I created to find this information:

<?xml version="1.0" encoding="UTF-8"?>
<ListView xmlns="http://soap.sforce.com/2006/04/metadata">

As you can see, they have different names than the user interface, especially things like CORE.USERS.ALIAS. Without creating a list view at least once, you're unlikely to guess most of the field names that are used.

  • Thank you and it really helps. Another question How do I get XML from a list?
    – Kishore
    Commented Feb 14, 2019 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .