Skip to main content
Skip table of contents

Resolve Error When Querying Account Fields during Account Merging


While attempting to merge accounts, if you're encountering the error "Error querying account fields. Be sure that the Account object does not contain a custom field with the same API name as a packaged field." this page will help you resolve that.

Background

This error occurs because there are Account or Contact fields in the Nimble AMS package that have the same API name as custom fields that your org has added to the Account or Contact object.

For example, Nimble AMS includes a field on the Contact object with the full API name NU__Degrees__pc. The person account merge fails if you have either:

  • A Contact field with the full API name of Degrees__pc or
  • An Account field with the full API name of Degrees__c

Tell Me More

There is a Salesforce platform limitation related to how Database.Query() parses the fields for account merging. The Nimble AMS person account merging functionality is included in the Nimble AMS package, which has the NU namespace, and the parser incorrectly assumes that NU is the namespace for every non-namespaced custom field on the Account and Contact object.

Resolving the Issue

One option is to change your custom field's API name so it no longer conflicts (Method 1).

However, we understand that that may be inconvenient or downright risky. For example, if your custom field is used in multiple integrations, changing the API name will break those integrations. So we offer another (albeit more technical) option if changing your field's API name is not an option (Method 2). 

Method 1: Change Your Custom Field Name

  1. Follow these steps from Salesforce: Error: 'Duplicate field selected' for Contacts merge in NPSP

This is a knowledge article that affects the Salesforce Nonprofit Success Pack (NPSP). Since it's a managed package like Nimble AMS (NU), it encounters the same problem when merging accounts.

Method 2: Add a Class that Overrides the Account Merge Tool's SOQL Query

  1. Create the AccountMergeExtension Apex class that implements the Salesforce Callable interface:

    Primary Code

    JAVA
    public with sharing class AccountMergeExtension implements Callable {
        public Object call(String action, Map<String, Object> args) {
            switch on action {
                when 'queryByIds' {
                    String query = (String)args.get('query');
                    Set<Id> ids = (Set<Id>)args.get('ids');
                    return this.queryByIds(query, ids);
                } when else {
                    // If we return null, the code in the NU package is prepared to fall back to the package query.
                    return null;
                }
            }
        }
    
        private List<SObject> queryByIds(String query, Set<Id> ids) {
            return Database.query(query);
        }
    }

    Test Code

    CODE
    @isTest
    public class AccountMergeExtensionTest {
    
        @isTest
        private static void call_nullAction_ExpectNullReturn() {
            AccountMergeExtension ext = new AccountMergeExtension();
            Object callResult = ext.call(null, null);
            
            System.assertEquals(null, callResult, 'Expected a call with null action to return null.');
        }
        
        @isTest
        private static void call_queryByIds_ExpectQueryList() {
            AccountMergeExtension ext = new AccountMergeExtension();
            Map<String, Object> args = new Map<String, Object>();
                 args.put('query', 'SELECT Id FROM Account LIMIT 1');
                
            Object callResult = ext.call('queryByIds', args);
            
            System.assert(callResult != null, 'Expected a queryByIds call to return a non-null result.');
        }
    }


  2. Create a new Event Handler custom metadata type record:

    FieldValue
    LabelMerge Accounts Extension
    Event Handler NameMergeAccountsExtension
    Event NameMergeAccountsExtension
    ClassAccountMergeExtension
    Is ActiveTRUE

Re-test

After following either method, try merging accounts again. The error should report back if there are any other conflicting fields. If it is still not working, contact Nimble AMS Support.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.