You need to sign in to do that
Don't have an account?
Andries.Neyens
Email2Case - Web2Case Remove automatic linking of Account/Contact to Case
Hi all,
I'm trying to remove the automatic linking of an PersonAccount to a Case with triggers, but no success:
Insert Before Case trigger: The link is not yet put into the account lookup field.
Insert After Case trigger: the automatic linking is available, so I try to remove it (with a future call ofcourse)
And what happens, it is linked again.
Same is happening if I do this via the Salesforce gui, edit the case, remove the account lookup and save: link is put back again
I'm trying to remove the automatic linking of an PersonAccount to a Case with triggers, but no success:
Insert Before Case trigger: The link is not yet put into the account lookup field.
Insert After Case trigger: the automatic linking is available, so I try to remove it (with a future call ofcourse)
And what happens, it is linked again.
Same is happening if I do this via the Salesforce gui, edit the case, remove the account lookup and save: link is put back again
....
if (trigger.isAfter && trigger.IsInsert) {
List<Case> casesToValidate = new List<Case>();
for(Case cse : (List<Case>)Trigger.new){
if (cse.AccountId!=null)
casesToValidate.add(cse);
}
if (casesToValidate.size() > 0)
ValidateBrandOfConnectedAccounts(casesToValidate); // will contstruct a Set of Case ID,s with some business logic and call UnlinkWrongConnectedCases
}
...
@future (callout=false)
private static void UnlinkWrongConnectedCases(Set<Id> cseIdSet){
if (cseIdSet==null || cseIdSet.size()==0) return; //bail out
List<Case> cseToUpdate = new List<Case>();
for(Id i:cseIdSet){
cseToUpdate.add(new Case(Id=i, AccountId=null)); //unlink the account
}
update cseToUpdate;
}
Anothier thing which I noticed is any particular reason you have marked the method to run in future coz future method runs Asynchronously and we can't predict when it is going to execute.
Debug logs are not saying anything, seems that salesforce is doing stuff just after the AFTER Update trigger...very weird
So,I don't thihnk you need a future method here as you are actually doing the same.
The Case has 2 lookup fields:
AccountId and ContactId,
For personAccount, those 2 fields are filled in with the same id.
So the solution was to blank out both fields instead of just one
cheers,