0

I have the following in my method called in after insert part of trigger.

public void caseAssignment(List<Case> cList){
    List<Case> cListNew = new List<Case>();
    AssignmentRule AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
    Id intId = [Select Id from user where name ='API User'].id;
    Database.DMLOptions dmlOpts = new Database.DMLOptions(); 
    dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
    for(Case c : cList){
        if(c.ownerId == intId && c.Source_Type__c != ''){
            c.setOptions(dmlOpts);
            cListNew.add(new case(Id = c.id));
        }    
    }
    system.debug('enterthedragon'+cListNew);
    database.update(cListNew);
}

But case owner is not changed to queue as defined in case assignment rules. system.debug is printing clistnew wit case id.

1 Answer 1

1

Problem is you are setting dml options to c variable(case) but in cListNew you are adding case by re instantiating it, so whatever dml options you applied got lost. I tried this in developer org and after below correction assignment rule started working.

    List<Case> cList = Trigger.new;//for testing purpose 
    List<Case> cListNew = new List<Case>();
    AssignmentRule AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
    Id intId = userinfo.getuserid();
    Database.DMLOptions dmlOpts = new Database.DMLOptions(); 
    dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
    for(Case c : cList){
        if(c.ownerId == intId && c.Source_Type__c != ''){
            system.debug('coming in this block');
            Case newCase = new case(Id = c.id);//Create instance and set dml options to that instance
            newCase.setOptions(dmlOpts);
            cListNew.add(newCase);
        }    
    }
    system.debug('enterthedragon'+cListNew);
    database.update(cListNew);

I hope this helps you.

1
  • Thansk Kiran.. will try this and let you know .. Thankyou
    – sf_user
    Dec 10, 2015 at 4:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .