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
Samantha ChuaSamantha Chua 

How to check if Attachment ID is null?

Hi!

I have the following button which executes if contact email is not null. However, I would like to check the presence of an attachment before sending the email. 

Can't seem to find the Attachment object though. Any idea how I can add an if condition for Attachment.Id != null?
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

var email = "{!Contact.Email}";

if (email != null)
{  
   sforce.apex.execute("sendWelcomeOfficialReceiptEmail","sendOfficialReceipt",{caseId:'{!Case.Id}', contactId:'{!Contact.Id}'});
   alert ('Email sent. Please refresh page and check activity history.');
} else {
alert ('Contact email is empty. Please specify email and try again.');
}

Regards,
Samantha
ManojjenaManojjena
Hi Samantha,

try with below code it will help !!
 
var relatedAtt=sforce.connection.query("SELECT id,ParentId FROM Attachment WHERE ParentId = "+ 
" '"+'{!Contact.Id}' +"' "); 
if(relatedAtt.size > 0) {
  //TO DO 

}
Let me know if it helps !!
Thanks
Manoj