function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jay reddyJay reddy 

Custom label (date value - today()+30) in apex class

Heya mates,

I'm trying to access a custom label in apex class but I guess I'm missing something.

My custom label: Date
value = System.today()+30

I'm referencing this custom label in apex class but it's throwing me an error as "invalid date"
 
Date endvalue = Date.valueOf(System.Label.Date);
        //String n = System.Label.Date_2;
        
        for(Contact con:scope) {
        
       
        if(date.valueof(con.License_Expiration_Date__c) == endvalue ) {
        
            Conlist.add(crew);
           }
          }
I really appreciate if someone could help me.
 
Best Answer chosen by Jay reddy
Raj VakatiRaj Vakati
You need to Maintain the   System.today()+30 in the custom  label .. Just add the 30 to the label and update the code as shwon below 

My custom label: Date
value = 30


 
String s =System.Label.Date ;
System.debug('s'+s);
Date endvalue = Date.valueOf(System.today()+Integer.valueOf(System.Label.Date));
System.debug('endvalue'+endvalue);
//String n = System.Label.Date_2;
      Date endvalue = Date.valueOf(System.today()+Integer.valueOf(System.Label.Date));
System.debug('endvalue'+endvalue);  


        for(Contact con:scope) {
        
       
        if(date.valueof(con.License_Expiration_Date__c) == endvalue ) {
        
            Conlist.add(crew);
           }
          }


 

All Answers

Raj VakatiRaj Vakati
You need to Maintain the   System.today()+30 in the custom  label .. Just add the 30 to the label and update the code as shwon below 

My custom label: Date
value = 30


 
String s =System.Label.Date ;
System.debug('s'+s);
Date endvalue = Date.valueOf(System.today()+Integer.valueOf(System.Label.Date));
System.debug('endvalue'+endvalue);
//String n = System.Label.Date_2;
      Date endvalue = Date.valueOf(System.today()+Integer.valueOf(System.Label.Date));
System.debug('endvalue'+endvalue);  


        for(Contact con:scope) {
        
       
        if(date.valueof(con.License_Expiration_Date__c) == endvalue ) {
        
            Conlist.add(crew);
           }
          }


 
This was selected as the best answer
Raj VakatiRaj Vakati
You  NO need to Maintain the   System.today()+30 in the custom  label .. Just add the 30 to the label and update the code as shwon below