1

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';
        filterListToAdd.add(filter);

        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 });
        MetadataService.handleSaveResults(results[0]);
0

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">
    <fullName>foo</fullName>
    <columns>ACCOUNT.NAME</columns>
    <columns>ACCOUNT.SITE</columns>
    <columns>ACCOUNT.ADDRESS1_STATE_CODE</columns>
    <columns>ACCOUNT.PHONE1</columns>
    <columns>ACCOUNT.TYPE</columns>
    <columns>CORE.USERS.ALIAS</columns>
    <filterScope>Everything</filterScope>
    <filters>
        <field>ACCOUNT.NAME</field>
        <operation>equals</operation>
        <value>Test</value>
    </filters>
    <label>foo</label>
    <language>en_US</language>
</ListView>

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 Feb 14 at 18:53

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.