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
Michael MMichael M 

Apex trigger- how to only include most recent content version in loop

Hello, I am working on Apex to collect the most recent content versions and attach them to an email. How would i write that condition? Here is the loop right now: 

if ..... what? I want all documents attached, but again, only the most recent contentversion of the documents. Thank you.

 for (ContentVersion cv : contentVersions) {
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            efa.setFileName(cv.Title + '.' + cv.FileExtension);
            efa.setBody(cv.VersionData);
            efa.setContentType('application/' + cv.FileExtension);
            fileAttachments.add(efa);

            mail.setFileAttachments(fileAttachments);
        }
 
Best Answer chosen by Michael M
Sri Arumilli 3Sri Arumilli 3
Hi Michael,
It looks like our team of experts can help you resolve this ticket.
We have Salesforce global helpdesk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our helpdesk. Trust me it is a support service that we are offering for free!

https://jbshelpdesk.force.com

Thanks,
Jarvis SFDC team

All Answers

Sri Arumilli 3Sri Arumilli 3
Hi Michael,
It looks like our team of experts can help you resolve this ticket.
We have Salesforce global helpdesk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our helpdesk. Trust me it is a support service that we are offering for free!

https://jbshelpdesk.force.com

Thanks,
Jarvis SFDC team
This was selected as the best answer
Sri Arumilli 3Sri Arumilli 3
Hi Michael,
Your ticket has now been updated with a solution.An email has been sent with an update
In case, if you haven't received any email , please click on the link below to check the solution:

https://jbshelpdesk.secure.force.com/CaseDetails?id=5002x000002pzLzAAI

Thanks,
Jarvis SFDC Team
Michael MMichael M
That's great, thank you. 

Is the service always free?
Sri Arumilli 3Sri Arumilli 3
Thanks you for using our service
This service is always free!

Please introduce our helpdesk to your organisation and we are happy to provide L1 and L2 support services free for life for the first 10 clients!

Thanks,
Jarvis SFDC Team
Michael MMichael M
Excellent, thank you, this is a great service!