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
Del_SantosDel_Santos 

Validate Attachment

Hi,

 

Can anyone tell me how can i create validation on leads' attachment? 

I have a requirement wherein there should be an attachment before i convert a lead to account.

 

 

Appreciate help. thanks. :))

 

Del

Avidev9Avidev9

I dont think this is possible using validation rule, but I guess can be done using trigger on lead.

Something like

 

trigger validateLeadConversion on Lead (after update) {
   Set<Id> attParentSet = new Set<Id>();
   for(Attachment att : [SELECT Id,ParentId FROM Attachment WHERE ParentId IN:trigger.new]){
       attParentSet.add(att.ParentId);
   }

   for(Lead l : trigger.New){
        if(l.isConverted == true && trigger.oldMap.get(l.Id).isConverted == false &&     (!attParentSet.contains(l.Id))){
              l.addError('You cannot convert the lead');
         }
   }
}

 

Del_SantosDel_Santos

Hi,

Thanks for this information. However, i am working on your example but receieved erreor like:

 

Error: Compile Error: Comparison arguments must be compatible types: SOBJECT:Lead, Boolean at line 10 column 33

 

Hope you can help me.

 

 

 

 

code:

===========

trigger validateLeadConversion on Lead (after update)
{
Set<Id> attParentSet = new Set<Id>();
for(Attachment att : [SELECT Id,ParentId FROM Attachment WHERE ParentId IN:trigger.new])
{
attParentSet.add(att.Id);
}
for(Lead l : trigger.New)
{
if(l.isConverted == true && trigger.oldMap.get(l.Id) == false && (!attParentSet.contains(l.Id)))
{
l.addError('Please add attachment before converting the lead'); }
}
}

Avidev9Avidev9
Man you should have spotted the typo in the code!!!!!
I already edited my answer please check
Del_SantosDel_Santos
Thanks!
Del_SantosDel_Santos

Hi, 

 

Thanks. Sorry. I have already updated the code. however, even my lead already has an attachment, the validation is still appearing.  I have attached my attachment to the standard Notes and Attachment related list.

 

Pls help.

 

Thanks,

Del

 

 

 

Avidev9Avidev9
What do you mean by attachment ?
Files ?
Or Notes ?
Del_SantosDel_Santos

Hi, thanks.

 

files. in form of email, excel, jpg, etc.

Avidev9Avidev9
I made a mistake. Just highlighted the same in the answer have a look
Del_SantosDel_Santos

same issue...:(

Del_SantosDel_Santos

Hello. 

Anyone can help me with this? :(

 

Thank you.

del

Avidev9Avidev9
Del it works for me.
Are you attaching a FILE or a Note ?

The code is designed for files