You need to sign in to do that
Don't have an account?
Michael M
Workaround error when merging person accounts: "name" is not writeable
I'm trying to merge 2 person accounts. However I am getting an error, stating that the "name" field is not writeable. I know that I have permissions, but it seems that on person accounts this field is not writeable when merging. How can I edit my code to work around that issue?
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, false );
}
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, false );
}
//** 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 );
}