You need to sign in to do that
Don't have an account?
SOQL Query for Newest Opportunity on Account
I'm trying to figure out how to write a SOQL query to display the newest opportunity associated with every account, using the MIN() SOQL aggregate function. Unfortunately, I can't seem to wrap my head around how to structure this since aggregate queries only let you include the field that you're grouping by and the field you're aggregating [Example: AccountId, MIN(CreatedDate) from Opportunity], however I also need to know the Id of each resulting opportunity so that I can utilize it in the trigger. How would I need to structure the query so that I can also extract the opportunity ID? Thanks!
All Answers
you can try this query
select id,name from opportunity
where accountid=:YourAccountId
order by createddate desc limit 1
replace YourAccountId with your actual account id..