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
DJPDJP 

Get Opportunities By DateTime

Hi
I need an APEX class to retrieve Opportunities based on passed CreatedDate field. Basically, I need APEX class which accepts dateTime as parameter and I can use it in where clause of my SQL - SELECT AccountId, ID, OwnerID, Name, Model__C FROM Opportunity  WHERE CreatedDate>='XXXXXXXXXXXX'.
The createDate is stored in 2017-09-12T22:26:37.000Z format. I dont know what is 000Z in this field value.  
Thanks

Dipa

 
SubratSubrat (Salesforce Developers) 
Hello ,

Here's an example Apex class that retrieves Opportunities based on a passed-in CreatedDate parameter:
public class RetrieveOpportunities {
    public static List<Opportunity> getOpportunitiesCreatedAfter(DateTime createDate) {
        return [SELECT AccountId, ID, OwnerID, Name, Model__C FROM Opportunity WHERE CreatedDate >= :createDate];
    }
}


This class accepts a DateTime parameter createDate and uses it in a SOQL query to retrieve Opportunities where the CreatedDate is greater than or equal to the passed-in createDate. Note that we're using the :createDate syntax to bind the parameter value to the SOQL query.

Regarding the 000Z at the end of the CreatedDate field value, it represents the time zone offset from Coordinated Universal Time (UTC). The Z indicates that the time is in UTC. In this case, 000Z indicates that the time zone offset is 0, meaning the time is in UTC with no offset.

Hope this helps !
Thank you.