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
Community_NameCommunity_Name 

Count on Attachments

Hi Everyone, 

i have a scenario where i have to count the attachments put it ina field on the parent record.

 

i have custom object called Opportunity Line items. in that object we have notes and attachments as a related list. 

and we have a field called count(checkbox) on opportunity line item. 

 

if the user comes and attach any document this field(count) on opportunity line item need to true. 

 

 

can anyone suggest me with some sample code how to do this.

 

thanks in advance.

 

Devendra@SFDCDevendra@SFDC

 

Hi,

 

As attachments are stored in Attachment object, you can query on Attachment object, use size() method to count the attachments on particular record.

 

List<Attachment> at=[Select id from Attachment where parentId=:'OpportunityLineItemRecordId'];
Integer count=at.size();
System.debug('Count is '+count);

 

Hope this helps.:)

 

Thanks,

Devendra