Skip to main content
deleted 25 characters in body
Source Link
trigger statusUpdateTrigger1 on Case (after update) {
List<Case> cases = new List<Case>(trigger.new);
       
        for(Case c : cases)
            {
              
                
                if(c.status != trigger.oldMap.get(c.id).status){
                   DateTime d1=c.CreatedDate;
                 
                  DateTime d2=c.LastModifiedDate;
                   decimal Hours = decimal.valueOf((d2.getTime() - d1.getTime()));
                   decimal hour1 = Hours/(1000*60*60);
                   
                   Integer min1 = Integer.valueOf(Hours/(1000*60));
                   min1=math.mod(min1,60);
                   
                  
                   String str1=String.valueOf(hour1);
                   string[] str2=str1.split('\\.');
                   string hour=str2[0];
                   string min=string.valueOf(min1);

                   String currStat=c.Status;
                   String casNum=c.CaseNumber;
                   CaseStatusDuration__c obj =new CaseStatusDuration__c();
                   obj.Duration__c=hour+':'+min;
                  
                   obj.caseNumber__c=casNum;casNum=c.caseNumber;
                   obj.Status__c=currStat;
                   obj.Case__c=c.id;
                   insert obj;
                      
                   }
            }
trigger statusUpdateTrigger1 on Case (after update) {
List<Case> cases = new List<Case>(trigger.new);
       
        for(Case c : cases)
            {
              
                
                if(c.status != trigger.oldMap.get(c.id).status){
                   DateTime d1=c.CreatedDate;
                 
                  DateTime d2=c.LastModifiedDate;
                   decimal Hours = decimal.valueOf((d2.getTime() - d1.getTime()));
                   decimal hour1 = Hours/(1000*60*60);
                   
                   Integer min1 = Integer.valueOf(Hours/(1000*60));
                   min1=math.mod(min1,60);
                   
                  
                   String str1=String.valueOf(hour1);
                   string[] str2=str1.split('\\.');
                   string hour=str2[0];
                   string min=string.valueOf(min1);

                   String currStat=c.Status;
                   String casNum=c.CaseNumber;
                   CaseStatusDuration__c obj =new CaseStatusDuration__c();
                   obj.Duration__c=hour+':'+min;
                  
                   obj.caseNumber__c=casNum;
                   obj.Status__c=currStat;
                   obj.Case__c=c.id;
                   insert obj;
                      
                   }
            }
trigger statusUpdateTrigger1 on Case (after update) {
List<Case> cases = new List<Case>(trigger.new);
       
        for(Case c : cases)
            {
              
                
                if(c.status != trigger.oldMap.get(c.id).status){
                   DateTime d1=c.CreatedDate;
                 
                  DateTime d2=c.LastModifiedDate;
                   decimal Hours = decimal.valueOf((d2.getTime() - d1.getTime()));
                   decimal hour1 = Hours/(1000*60*60);
                   
                   Integer min1 = Integer.valueOf(Hours/(1000*60));
                   min1=math.mod(min1,60);
                   
                  
                   String str1=String.valueOf(hour1);
                   string[] str2=str1.split('\\.');
                   string hour=str2[0];
                   string min=string.valueOf(min1);

                   String currStat=c.Status;
                   String casNum=c.CaseNumber;
                   CaseStatusDuration__c obj =new CaseStatusDuration__c();
                   obj.Duration__c=hour+':'+min;
                  
                   obj.casNum=c.caseNumber;
                   obj.Status__c=currStat;
            
                   insert obj;
                      
                   }
            }
added 1888 characters in body
Source Link

I have written a trigger.. But there is some mistake i could not find... please Help me and modify the error.

I create an Object: CaseStatusDuration Three fields are there: 1>currStat 2>casNum 3>Duration__c(Field Type:Date/Time)

When a case status will change then the Duration between two status will be save to that object CaseStatusDuration in Duration field.

trigger statusUpdateTrigger1 on Case (after update) {
List<Case> cases = new List<Case>(trigger.new);
       
        for(Case c : cases)
            {
              
                
                if(c.status != trigger.oldMap.get(c.id).status){
                   DateTime d1=c.CreatedDate;
                 
                  DateTime d2=c.LastModifiedDate;
                   decimal Hours = decimal.valueOf((d2.getTime() - d1.getTime()));
                   decimal hour1 = Hours/(1000*60*60);
                   
                   Integer min1 = Integer.valueOf(Hours/(1000*60));
                   min1=math.mod(min1,60);
                   
                  
                   String str1=String.valueOf(hour1);
                   string[] str2=str1.split('\\.');
                   string hour=str2[0];
                   string min=string.valueOf(min1);

                   String currStat=c.Status;
                   String casNum=c.CaseNumber;
                   CaseStatusDuration__c obj =new CaseStatusDuration__c();
                   obj.Duration__c=hour+':'+min;
                  
                   obj.caseNumber__c=casNum;
                   obj.Status__c=currStat;
                   obj.Case__c=c.id;
                   insert obj;
                      
                   }
            }

}

I have written a trigger.. But there is some mistake i could not find... please Help me and modify the error.

I create an Object: CaseStatusDuration Three fields are there: 1>currStat 2>casNum 3>Duration__c(Field Type:Date/Time)

When a case status will change then the Duration between two status will be save to that object CaseStatusDuration in Duration field.

trigger statusUpdateTrigger1 on Case (after update) {
List<Case> cases = new List<Case>(trigger.new);
       
        for(Case c : cases)
            {
              
                
                if(c.status != trigger.oldMap.get(c.id).status){
                   DateTime d1=c.CreatedDate;
                 
                  DateTime d2=c.LastModifiedDate;
                   decimal Hours = decimal.valueOf((d2.getTime() - d1.getTime()));
                   decimal hour1 = Hours/(1000*60*60);
                   
                   Integer min1 = Integer.valueOf(Hours/(1000*60));
                   min1=math.mod(min1,60);
                   
                  
                   String str1=String.valueOf(hour1);
                   string[] str2=str1.split('\\.');
                   string hour=str2[0];
                   string min=string.valueOf(min1);

                   String currStat=c.Status;
                   String casNum=c.CaseNumber;
                   CaseStatusDuration__c obj =new CaseStatusDuration__c();
                   obj.Duration__c=hour+':'+min;
                  
                   obj.caseNumber__c=casNum;
                   obj.Status__c=currStat;
                   obj.Case__c=c.id;
                   insert obj;
                      
                   }
            }

}

Source Link

Need to show the time between case status change using trigger?

I need to catch the time when a case status is changed from one status to another. like a case is in new status now its change to working or a case is in working and when it is changed to escalated . I want the time between one case status to another . please Help me, How can i achieve this task???