• Eric Baniqued
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I'm no expert in writing apex codes and I've just got this code below to work in the sandbox environment. What this does is that it changes the case status to In Progress when an agent accepts a case from omni channel. I've tried to deploy it in production but its not letting me as I am getting an error for code coverage. I dont have any idea on how to write a test class for AgentWork as I can't find many detailed examples that I can relate my code and study to write it from scratch. 

trigger Omni_Work_Status on AgentWork (after update) {
    for ( AgentWork newAW : Trigger.new){

        AgentWork oldAW = Trigger.oldMap.get(newAW.Id);
        Boolean acceptedWork = oldAW.AcceptDatetime != newAW.AcceptDatetime;

        if ( acceptedWork ){

        String workitemId = newAW.WorkItemId;

        try{
            
            Case c = [SELECT Status FROM Case WHERE Id =: workitemId ];

            c.Status = 'In Progress';

            update c;

        } catch (exception e){

            //do nothing

            System.debug('error message: '+ e.getMessage());

            }
        }
    }
}
I'm no expert in writing apex codes and I've just got this code below to work in the sandbox environment. What this does is that it changes the case status to In Progress when an agent accepts a case from omni channel. I've tried to deploy it in production but its not letting me as I am getting an error for code coverage. I dont have any idea on how to write a test class for AgentWork as I can't find many detailed examples that I can relate my code and study to write it from scratch. 

trigger Omni_Work_Status on AgentWork (after update) {
    for ( AgentWork newAW : Trigger.new){

        AgentWork oldAW = Trigger.oldMap.get(newAW.Id);
        Boolean acceptedWork = oldAW.AcceptDatetime != newAW.AcceptDatetime;

        if ( acceptedWork ){

        String workitemId = newAW.WorkItemId;

        try{
            
            Case c = [SELECT Status FROM Case WHERE Id =: workitemId ];

            c.Status = 'In Progress';

            update c;

        } catch (exception e){

            //do nothing

            System.debug('error message: '+ e.getMessage());

            }
        }
    }
}