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
Max_gMax_g 

Need to get current year records from custom object where year is in a text field.

I need to be able to select current year records from a sales history custom object.  The sales year is a text field in the format of CCYY. 

 

How do I code for this in my trigger select statement?

 

Best Answer chosen by Admin (Salesforce Developers) 
Andrew WilkinsonAndrew Wilkinson

Do you mean you want to look at the current year today and grab those from your query/

 

If so it would look something like this...

 

String dateOfToday = String.valueOf(Date.today().year());

 

Then your SOQL would include this in the where clause...I am assuming the API name of your field

 

WHERE Sales_Year__c = :dateOfToday

All Answers

Andrew WilkinsonAndrew Wilkinson

Do you mean you want to look at the current year today and grab those from your query/

 

If so it would look something like this...

 

String dateOfToday = String.valueOf(Date.today().year());

 

Then your SOQL would include this in the where clause...I am assuming the API name of your field

 

WHERE Sales_Year__c = :dateOfToday

This was selected as the best answer
Max_gMax_g

Thanks for the quick update.  Solved my problem