• Daan Luttik
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Our goal is to merge Contacts (and later Accounts) in Salesforce CRM. Our data is already polluted therefore we can't rely on merge rules that are triggered only for new/changed contacts.

Therefore we think that we need to utilize Apex code however we are running into some issues that seem to have to do not with the code but with the permissions:
(Important to note about the code below, the emails in the contacts are fake and can therefore be ignored completely when merging).
public class MergeRule {
    public static void applyMergeRule() {
        AggregateResult[] contacts = [
            SELECT Name, BirthDate, COUNT(Email) nr
            FROM Contact GROUP BY Name, BirthDate
            HAVING COUNT(Email)>1
        ];
        for (AggregateResult contact_group: contacts) {
            String name = (String)contact_group.get('Name');
            Date birth_date = (Date)contact_group.get('BirthDate');
            Contact[] contact_subgroup = [
                SELECT Id, Name, BirthDate
                FROM Contact
                   WHERE Contact.Name = :name
                   AND Contact.BirthDate = :birth_date
						];
            for (Integer i=1; i<contact_subgroup.size(); i++){
								// This line produces the error 👇 🔔
                merge contact_subgroup[0] contact_subgroup[i];
            }
        }
    }
}

We receive the following error:
14:07:03:138 FATAL_ERROR System.DmlException: Merge failed. First exception on row 0 with id 0035r000002VYMoAAO; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
We have tried to change the field level security for the profile System Admin on the field Name for the Contacts object, however, we found that there is no way to change this field. We tried this due to the suggestions in this thread on the salesforce development forum (https://developer.salesforce.com/forums/?id=9060G0000005PvhQAE) and this thread on the salesforce stackexchange (https://salesforce.stackexchange.com/questions/69857/how-to-check-whether-a-user-has-write-access-to-a-field), however, we are not completely sure that we interpreted these threads correctly (maybe we need to change the permissions for other profiles, objects or fields instead of the ones above?)

I hope that you can help us with this issue.
Our goal is to merge Contacts (and later Accounts) in Salesforce CRM. Our data is already polluted therefore we can't rely on merge rules that are triggered only for new/changed contacts.

Therefore we think that we need to utilize Apex code however we are running into some issues that seem to have to do not with the code but with the permissions:
(Important to note about the code below, the emails in the contacts are fake and can therefore be ignored completely when merging).
public class MergeRule {
    public static void applyMergeRule() {
        AggregateResult[] contacts = [
            SELECT Name, BirthDate, COUNT(Email) nr
            FROM Contact GROUP BY Name, BirthDate
            HAVING COUNT(Email)>1
        ];
        for (AggregateResult contact_group: contacts) {
            String name = (String)contact_group.get('Name');
            Date birth_date = (Date)contact_group.get('BirthDate');
            Contact[] contact_subgroup = [
                SELECT Id, Name, BirthDate
                FROM Contact
                   WHERE Contact.Name = :name
                   AND Contact.BirthDate = :birth_date
						];
            for (Integer i=1; i<contact_subgroup.size(); i++){
								// This line produces the error 👇 🔔
                merge contact_subgroup[0] contact_subgroup[i];
            }
        }
    }
}

We receive the following error:
14:07:03:138 FATAL_ERROR System.DmlException: Merge failed. First exception on row 0 with id 0035r000002VYMoAAO; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
We have tried to change the field level security for the profile System Admin on the field Name for the Contacts object, however, we found that there is no way to change this field. We tried this due to the suggestions in this thread on the salesforce development forum (https://developer.salesforce.com/forums/?id=9060G0000005PvhQAE) and this thread on the salesforce stackexchange (https://salesforce.stackexchange.com/questions/69857/how-to-check-whether-a-user-has-write-access-to-a-field), however, we are not completely sure that we interpreted these threads correctly (maybe we need to change the permissions for other profiles, objects or fields instead of the ones above?)

I hope that you can help us with this issue.