• AISHIK BANERJEE 15
  • NEWBIE
  • 30 Points
  • Member since 2023

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am writing a trigger where I am bringing in a Date/Field field from case. It has a letter in it 2023-02-10T16:15:35.000+0000 and when I try to subtract it with "DateTime.now()" I get an error "Date/time expressions must use Integer or Double or Decimal ".

This is my code 
trigger CaseTrigger on Case (before update) {
     for(Case cases: Trigger.new){ 
         if(cases.stopped_time__c != null){
             cases.Total_amount_of_time_in_Hours__c= (DateTime.now()-cases.stopped_time__c );
         } 
    }
}
trigger preventAccDel on Account (before delete) {
    List<Id> accountIds=new List<Id>();
    Integer count=0;
    for(Account acc:Trigger.New){
        accountIds.add(acc.Id);
    }
    for(Account a:[SELECT Id, Name, (SELECT Id, AccountId FROM Contacts) FROM Account where Id IN :accountIds]){
        for(Contact con:a.Contacts){
            count=count+1;
        }
        if(count>=2){
            a.addError('This Account is associated with 2 or more Contact records. Hence cannot be deleted');
        }
        count=0;
    }
}
I am writing a trigger where I am bringing in a Date/Field field from case. It has a letter in it 2023-02-10T16:15:35.000+0000 and when I try to subtract it with "DateTime.now()" I get an error "Date/time expressions must use Integer or Double or Decimal ".

This is my code 
trigger CaseTrigger on Case (before update) {
     for(Case cases: Trigger.new){ 
         if(cases.stopped_time__c != null){
             cases.Total_amount_of_time_in_Hours__c= (DateTime.now()-cases.stopped_time__c );
         } 
    }
}
trigger preventAccDel on Account (before delete) {
    List<Id> accountIds=new List<Id>();
    Integer count=0;
    for(Account acc:Trigger.New){
        accountIds.add(acc.Id);
    }
    for(Account a:[SELECT Id, Name, (SELECT Id, AccountId FROM Contacts) FROM Account where Id IN :accountIds]){
        for(Contact con:a.Contacts){
            count=count+1;
        }
        if(count>=2){
            a.addError('This Account is associated with 2 or more Contact records. Hence cannot be deleted');
        }
        count=0;
    }
}
I am writing a trigger where I am bringing in a Date/Field field from case. It has a letter in it 2023-02-10T16:15:35.000+0000 and when I try to subtract it with "DateTime.now()" I get an error "Date/time expressions must use Integer or Double or Decimal ".

This is my code 
trigger CaseTrigger on Case (before update) {
     for(Case cases: Trigger.new){ 
         if(cases.stopped_time__c != null){
             cases.Total_amount_of_time_in_Hours__c= (DateTime.now()-cases.stopped_time__c );
         } 
    }
}