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 n12SFDC n12 

notes and attachment validation


I am having the notes and attachments section as a related list on a custom object,

on save i have a trigger which is firing a approval process on my customobject

my scenario is when no record is attached under notes and attachment it should throw an error befre save "please enter value for notes and attachment" preventing the approval process not to fire

if attachment is present then no error should be thrown and record can be saved

can a validation rule help on this case

let me know how to do it

below is my trigger for approval process

trigger SubmitForApproval on Special_Programs_ADR_Exception__c (after update, after insert) {
        for (Integer i = 0; i <; i++) {
            if ([i].RoutenotifytoSalesSpecialist__c !=null &&[i].DOSUser__c !=null &&[i].RVP_Approver__c !=null) {

                // create the new approval request to submit
                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                req.setComments('Submitted for approval. Please approve.');
                req.setNextApproverIds(new List<Id>{[i].ownerId});
                // submit the approval request for processing
                Approval.ProcessResult result = Approval.process(req);
                // display if the reqeust was successful
                System.debug('Submitted for approval successfully: '+result.isSuccess());
    }catch(System.DMLException e) { }

Thnks in advance

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Unfortunatly this is not possible. Other approch I would suggest is to have One custom chackbox field on you object which will be updated using attachement trigger whenever attachemnt is added to your custom object record.
Then depending on checkbox is checked or unchecked you can have validation rule to add error message before approval.

SFDC n12SFDC n12
 ok fine,

can you help me with the trigger  based on notes and attachments

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Have a look at this sample code :

trigger SetTitleToAttachment on Attachment (after insert) {
	String Title;
	Id pId;

	for(Attachment att:{
	List<Case> c=[select Id , Title__c from Case where Id=:pId];
	//assuming one record is fetched.

	update c[0];