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
SFDC DummySFDC Dummy 

How to count number of attachment on a custom object:urgent.

Hi 

How to count number of attachment on a particular custom object ..
TabrezTabrez

public List<Attachment> attachments = new Attachments();

 public String soql;
 
soql = 'Select Id, Name From Attachment where parentid IN : parentId' ; 
 
attachments = Database.query(soql);
      
sCount = attachments.size();

System.debug(sCount);
Hi,

I hope this will work, you just need to pass the parent custom object id to this soql string and that will return the number of attachment.
Vijay NagarathinamVijay Nagarathinam
Hi SFDC Dummy,

Refer the following site, it will be helpful for your requiremnt.

http://techysunil.blogspot.in/2015/04/trigger-to-count-number-of-attachments.html