1

I m doing merging using MergeRequest at Visualforce side,

for(var i=0;i < records.length;i++){
    if(i==masterRecordIndex){
        continue;
    }else{
        var mergeRequest=new sforce.MergeRequest();
        mergeRequest.masterRecord=objMaster;  
        mergeRequest.recordToMergeIds=records[i].Id;
        mergeRequests.push(mergeRequest);                   
    }
}           
var callback={
    onSuccess:onSuccess,
    onFailure:onFailure
};

sforce.connection.merge(mergeRequests,callback);

It works fine except for certain account it will gave this error

The accounts cannot be merged. Selected records do not have compatible portal types and cannot be merged together.

I read the solution How do I merge Accounts that each have Partner and Customer Portal Users associated? but I don't know how to implement this using code.Do I need update some fields,if yes what field?

1

Basically you are trying to merge 2 active portal accounts of different type together. I gonna try to translate what Salesforce is proposing. I don't think doing this by Javascript will be the easiest, but here is the idea.

So you have 2 different Accounts:

Acct1 - Partner Portal

Acct2 - Customer Portal

  1. The first thing to do is to create a temporary account(Acct3) with basic/required fields.

    Account Acct3 = new Account();
    //default basic fields
    insert Acct3;
    
  2. Reparent all the contacts from both account(Acct1 and Acct2) to Acct3.

    List<Contact> contacts = [SELECT Id FROM Contact WHERE AccountId = :Acct1.Id OR AccountId = :Acct2.Id];
    for(Contact cont : contacts) cont.AccountId = Acct3.Id;
    update contacts;
    
  3. Disable Acct2 as a customer portal account

    Acct2.IsCustomerPortal = false;  //for Partner Account, user IsPartner
    update Acct2;
    
  4. Now you need to make the merge. Your Acct1 should still be enabled. I think you know how to do that.

  5. Reparent all contacts from Acct3 to Acct1(from step 2)

    for(Contact cont : contacts) cont.AccountId = Acct1.Id;
    update contacts;
    

I never try myself, but I think it should work. Now I'm not sure if you actually need step 1 and create a temporary account(Acct3), or could you just reparent directly all the contact from Acct2 to the partner account (Acct1). I'm interested to see the output if you could let us know. Good Luck!

| improve this answer | |

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.