function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jerry ClifftJerry Clifft 

Drawing a blank, how to update cases related to an account, when the account is updated?

Issue I am trying to reslove:
I have a case or two open, it / they are sitting in a queue called "Delinquency Hold".

The first part of the process, this works fine.
The account has a multipick select list called Flags__c, one of the values is Delinquent. When a new case is created, or an open case is edited, the case check's this field on the account, and if the Flags__c includes "Delinquent" it moves the case ownership to Delinquency Hold and displays a large red note across the top of the page.

Here is where I am drawing a blank.
If the account field Flags__c has the value ""Delinquent" removed, I need to have all cases that are Status = Open and Owner = Queue/Delinquency Hold re-visit the the case assignment rules so the case can re-routed/worked.

Idea's, Suggestions?
Best Answer chosen by Jerry Clifft
Vinit_KumarVinit_Kumar
Then,you need the Trigger on Account not on case and fetch the related Cases based on AccountId and set the Assignment rule,something like below :-

trigger updateRelatedCases  on Account(before update)
{

List<Id> accIds = new List<Id>();
List<Case> updatedList = new List<Case>();
	for(Account acc:trigger.new)
	{
		accIds.add(acc.id);
	}
	
	List<Case> caseList =  [select id from Case where AccountId in;accIds];
	
	for (Case theCase:caseList) {
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.emailHeader.triggerUserEmail = true;
                dmo.assignmentRuleHeader.AssignmentRuleId= <Id of assignment rule>;//You can query the 
i//d from Assignement Rule object
                theCase.setOptions(dmo);
                 updatedList.add(theCase);

}

if(updatedList.size()>0)
{
	Database.update(updatedList);   
}

}

If this helps,please mark it as best answer to help others :)

All Answers

Ramu_SFDCRamu_SFDC
You might have to check the below article

http://developer.force.com/cookbook/recipe/running-case-assignment-rules-from-apex
Vinit_KumarVinit_Kumar
Standard Assignment rule would only fire when a case is created,if you want to execute the Assignment rule to fire when it's edited.You need to create a update Trigger on Case which would use.Sample case would be something like below :-

for (Case theCase:trigger.new) {
            if(theCase.Origin == 'Web') {
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.emailHeader.triggerUserEmail = true;
                dmo.assignmentRuleHeader.AssignmentRuleId= <Id of assignment rule>;//You can query the 
i//d from Assignement Rule object
                theCase.setOptions(dmo);
                Database.update(theCase);    
            }

If this helps,please mark it as best answer to help others :)
Jerry ClifftJerry Clifft
I can see that working on the case if the case is ineserted / updated. But how would I call that trigger on the case, if / when the account object / record is updated, and not the case?
Vinit_KumarVinit_Kumar
Then,you need the Trigger on Account not on case and fetch the related Cases based on AccountId and set the Assignment rule,something like below :-

trigger updateRelatedCases  on Account(before update)
{

List<Id> accIds = new List<Id>();
List<Case> updatedList = new List<Case>();
	for(Account acc:trigger.new)
	{
		accIds.add(acc.id);
	}
	
	List<Case> caseList =  [select id from Case where AccountId in;accIds];
	
	for (Case theCase:caseList) {
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.emailHeader.triggerUserEmail = true;
                dmo.assignmentRuleHeader.AssignmentRuleId= <Id of assignment rule>;//You can query the 
i//d from Assignement Rule object
                theCase.setOptions(dmo);
                 updatedList.add(theCase);

}

if(updatedList.size()>0)
{
	Database.update(updatedList);   
}

}

If this helps,please mark it as best answer to help others :)
This was selected as the best answer
Jerry ClifftJerry Clifft
That is exactly perfect! Vinit_Kumar

I made a few minor modifacations to fit my exact circumstance.

trigger updateRelatedCases  on Account(before update)
{

List<Id> accIds = new List<Id>();
List<Case> updatedList = new List<Case>();
    for(Account acc:trigger.new)
    {
        accIds.add(acc.id);
    }
   
    List<Case> caseList =  [select id, OwnerId from Case where AccountId in:accIds AND OwnerID = '00G60000002Ia7P'];
               // Add OwnerID = Delinquent Queue, as only those should be proccesed.
    List<Account> accountList =  [select id, Flags__c from Account where Id in:accIds AND Flags__c != 'Delinquent'];
              // Add Flags__c != Delinquent, So this trigger only enters the for loop for accounts that not Delinquent and should not have cases on Delinquent hold.
   
    if(caseList.size()>0 && accountList.size()>0)
    for (Case theCase:caseList) {
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.emailHeader.triggerUserEmail = true;
                dmo.assignmentRuleHeader.AssignmentRuleId='01Q60000000Qu6U'; //You can query the id from Assignement Rule object
                theCase.setOptions(dmo);
                 updatedList.add(theCase);

}

if(updatedList.size()>0 )
{
    Database.update(updatedList);  
}

}
Vinit_KumarVinit_Kumar
Happy to help !!

One more suggestion rather than hard coding the Id of queu,you should be querying it and similarily for Assignment Rule id,something like below :-

Queue q = [select id from Queue where name='Delinquent'];