Skip to main content
Athira Venugopal ha fatto una domanda in #Lightning Experience
Anyone please help me!!

I just created a formula field to calculate  the time spent between status changes 'New' and 'Closed'. But it's not user specific. ie, if im the one who logged in i want to see the time i had spend on that.
3 risposte
  1. 28 gen 2021, 04:46

    Well since spring 21 still isn't fully out otherwise could have achieve the below with that but with trigger here it is

    • First you can create an custom SObject Case Workflow with the following fields
    Well since spring 21 still isn't fully out otherwise could have achieve the below with that but with trigger here it isFirst you can create an custom SObject Case Workflow with the following fieldsYou

    You can use the following trigger, please note this is just to give you an idea. You can change the trigger as per your need

    trigger CaseStatusWorkflowTrigger on Case (after insert, after update) {

    List<Case_Workflow__c> cwToInsertList = new List<Case_Workflow__c>();

    for(Case caseRec : trigger.new){

    if(trigger.oldMap == null || (caseRec.Status != trigger.oldMap.get(caseRec.Id).Status))

    {

    Case_Workflow__c cwToInsert = new Case_Workflow__c();

    cwToInsert.OldValue__c = trigger.oldMap?.get(caseRec.Id).Status;

    cwToInsert.NewValue__c = caseRec.Status;

    cwToInsert.FieldName__c = 'Status';

    cwToInsert.Case__c = caseRec.Id;

    cwToInsertList.add(cwToInsert);

    }

    }

    if(!cwToInsertList.isEmpty())

    Database.insert(cwToInsertList);

    }

    Test class

    @isTest

    public class CaseStatusWorkflowTest {

    private static testMethod void testCaseStatusWorkflowOnInsert() {

    Test.startTest();

    Case caseRec = new Case(Status = 'Open', Origin = 'Phone');

    insert caseRec;

    Test.stopTest();

    Case_Workflow__c cw = [SELECT Id, OldValue__c, NewValue__c FROM Case_Workflow__c WHERE Case__c = :caseRec.Id];

    system.assert(cw.OldValue__c == null);

    system.assert(cw.NewValue__c == 'Open');

    }

    }

     
0/9000