1

I have a workflow rule that changes the case status to "SHIFTED" when the case owner is changed from one user/queue to another user/queue.

The Evaluation criteria is when a record is created, and every time it's edited.

The Rule criteria:
AND( 
ISCHANGED(OwnerId), 
OR(LEFT(PRIORVALUE(OwnerId),3)="005", LEFT(PRIORVALUE(OwnerId), 3)="00G"))

Workflow Action is the Field Update to New Field Value: SHIFTED.

It is working fine. But now the new criteria is, if the Case Status is "PROGRESS" then the workflow should not be fired. As the ISCHANGED function has been used, the "created, and any time it’s edited to subsequently meet criteria" cannot be chosen. I'm trying to achieve this task using Trigger. I've started(given below) but not sure how to proceed as I'm not good in triggers. If you could help me in this trigger or any other suggestions would be great.

trigger ChangeOwnerStatusIsShifted on Case (before update) {
List<Case> cases = new List<Case>();
for(Case c: Trigger.new){
    if(c.Status == 'Submitted'){
        cases.add(c);
    }
    //Code to allow changing the case owners for the cases with other Status 
  }
}
1

You can use a Workflow or a Trigger.

Workflow:

AND( 
    NOT(ISPICKVAL(Status,'PROGRESS'))
    ISCHANGED(OwnerId), 
    OR(LEFT(PRIORVALUE(OwnerId),3)="005", LEFT(PRIORVALUE(OwnerId), 3)="00G")
)

Trigger

trigger ChangeOwnerStatusIsShifted on Case (before update) {
Case newCase;
Case oldCase;
for(String caseId: Trigger.newMap.keySet()){
    newCase = Trigger.newMap.get(caseId);
    oldCase = Trigger.oldMap.get(caseId);
    if(newCase.Status != 'PROGRESS' && newCase.OwnerId != oldCase.OwnerId){
        newCase.Status = 'SHIFTED';
    }
  }
}

Regards

| improve this answer | |
0

Based on your requirement, the trigger can be structured like this.

trigger ChangeOwnerStatusIsShifted on Case (before update) {
List<Case> cases = new List<Case>();
for(Case c: Trigger.new){
    Case oc = Trigger.oldMap.get(c.Id);
    if (c.Status <> 'Progress' && c.OwnerId <> oc.OwnerId) {
        cases.add(c);
    }
}
if (cases.size() > 0) {
    //Code to allow changing the case owners for the cases with other Status
}
}
| improve this answer | |
  • Thank you @ntnng. So the code to allow cases not in the list to edit or allow the cases in the list not to edit the OWNER field is just 'CONTINUE;' or how can it be stated, using 'ISUPDATE' or any other? Thanks – Seesh Jun 3 '14 at 15:41
0

I have some complex solution for you: Here is trigger and class - as it is not best practise to have code in triggers. (As it was created in NotePade++ it might need some changes in your env. :) )

trigger ChangeOwnerStatusIsShifted on Case (before update) {
    CaseHelper.changeStatus(trigger.new, trigger.oldMap); 
}

public class CaseHelper{
    public static changeStatus(Case[] newCases, MAp<Id,Case> oldCases){
        List<Case> cases = new List<Case>();
        for(Case c: newCases){

            if(c.Status == 'PROGRESS'){
                continue;
            }

            if(checkWFCriteria(c.Id, oldCases.get(c.Id).Id)){
                c.Status = 'SHIFTED';
                cases.add(c);
            }
        }

        if(!cases.isEmpty()){
            update cases;
        }
    }

    private Boolean checkWFCriteria( Id oldOwnerId, Id newOwnerId){
        Set<String> avalibleObjects = new Set<String>{'User', 'Group'} 
        return  oldOwnerId != newOwnerId
                && avalibleObjects.contains(oldOwnerId.getSObjectType().getDescribe().getName())
                && avalibleObjects.contains(newOwnerId.getSObjectType().getDescribe().getName())
    }
}
| 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.