You need to sign in to do that
Don't have an account?
Michael M
Error when trying to merge person accounts
Hello, I'm trying to merge 2 person accounts, and getting an error. The error is this:
"Line: 21, Column: 1
System.DmlException: Merge failed. First exception on row 0 with id 0016300000lyQrIAAU; 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]"
The code is this:
//** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , name, patient_dob__c
FROM Account
WHERE IsPersonAccount=TRUE
and name like '%James Dean%'
GROUP BY Name, Patient_DOB__c
HAVING Count(ID) > 1
ORDER BY Count(ID) desc
LIMIT 2000];
For (AggregateResult Agm : MyMergeList){
//** Tweak the string parameters to match your preference (confidence)....
//String accName = '%'+ string.valueOf(agm.get('Name')) + '%';
String accName = string.valueOf(agm.get('Name'));
Account ToAccount = [Select id, name from account where name like :accName limit 1];
Account FromAccount = [Select id, name from account where Id != :ToAccount.Id and name like :accName Limit 1];
system.debug(LoggingLevel.Info,'*** FromAccount: ' + FromAccount.Name+' ('+FromAccount.Id+')');
system.debug(LoggingLevel.Info,'*** ToAccount : ' + ToAccount.Name+' ('+ToAccount.Id+')');
database.merge(ToAccount , FromAccount );
}
"Line: 21, Column: 1
System.DmlException: Merge failed. First exception on row 0 with id 0016300000lyQrIAAU; 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]"
The code is this:
//** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , name, patient_dob__c
FROM Account
WHERE IsPersonAccount=TRUE
and name like '%James Dean%'
GROUP BY Name, Patient_DOB__c
HAVING Count(ID) > 1
ORDER BY Count(ID) desc
LIMIT 2000];
For (AggregateResult Agm : MyMergeList){
//** Tweak the string parameters to match your preference (confidence)....
//String accName = '%'+ string.valueOf(agm.get('Name')) + '%';
String accName = string.valueOf(agm.get('Name'));
Account ToAccount = [Select id, name from account where name like :accName limit 1];
Account FromAccount = [Select id, name from account where Id != :ToAccount.Id and name like :accName Limit 1];
system.debug(LoggingLevel.Info,'*** FromAccount: ' + FromAccount.Name+' ('+FromAccount.Id+')');
system.debug(LoggingLevel.Info,'*** ToAccount : ' + ToAccount.Name+' ('+ToAccount.Id+')');
database.merge(ToAccount , FromAccount );
}
//** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , name, patient_dob__c
FROM Account
WHERE IsPersonAccount=TRUE
and name like '%James Dean%'
GROUP BY Name, Patient_DOB__c
HAVING Count(ID) > 1
ORDER BY Count(ID) desc
LIMIT 2000];
For (AggregateResult Agm : MyMergeList){
//** Tweak the string parameters to match your preference (confidence)....
//String accName = '%'+ string.valueOf(agm.get('Name')) + '%';
String accName = string.valueOf(agm.get('Name'));
Account ToAccount = [Select id, firstname, lastname from account where name like :accName limit 1];
Account FromAccount = [Select id, firstname, lastname from account where Id != :ToAccount.Id and name like :accName Limit 1];
system.debug(LoggingLevel.Info,'*** FromAccount: ' + FromAccount.firstname+' ('+FromAccount.Id+')');
system.debug(LoggingLevel.Info,'*** ToAccount : ' + ToAccount.firstname+' ('+ToAccount.Id+')');
database.merge(ToAccount , FromAccount );
}
All Answers
Greetings!
Can you please double check the FLS of the Name field for the affected user's profile or permission set which has been assigned for the user as per the error message.
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
The field level security is set to "Visible" for my profile. I also have modify all permission on the account object and edit access on the name field.
//** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , name, patient_dob__c
FROM Account
WHERE IsPersonAccount=TRUE
and name like '%James Dean%'
GROUP BY Name, Patient_DOB__c
HAVING Count(ID) > 1
ORDER BY Count(ID) desc
LIMIT 2000];
For (AggregateResult Agm : MyMergeList){
//** Tweak the string parameters to match your preference (confidence)....
//String accName = '%'+ string.valueOf(agm.get('Name')) + '%';
String accName = string.valueOf(agm.get('Name'));
Account ToAccount = [Select id, firstname, lastname from account where name like :accName limit 1];
Account FromAccount = [Select id, firstname, lastname from account where Id != :ToAccount.Id and name like :accName Limit 1];
system.debug(LoggingLevel.Info,'*** FromAccount: ' + FromAccount.firstname+' ('+FromAccount.Id+')');
system.debug(LoggingLevel.Info,'*** ToAccount : ' + ToAccount.firstname+' ('+ToAccount.Id+')');
database.merge(ToAccount , FromAccount );
}