+ Start a Discussion
Roger Bannister 53Roger Bannister 53 

Button code to select most recent document from Files?

I have a custom button on the Quote object that, as part of it's function, I want it to select only the most recent document from the 'Files' related list to be sent out.

Right now it 'grabs' all the files in the related list - is there some code I can add to the button that limits it to only the most recent file? What would that code look like?

Thanks, Roger
Abhishek BansalAbhishek Bansal
Hi Roger,

You can use the ORDER BY clause along with the LIMIT clause to limit your search for the most recent file.
Select Id from Attachment ORDER BY CreatedDate DESC LIMIT 1

Let me know if you need any further help on this.

Abhishek Bansal.