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
dreamrealdreamreal 

Trigger Error : Method does not exist or incorrect signature

I'm trying to create a trigger to send an email with an attachment from the "notes and attachments'" object. However it wont compile and give the error: Method does not exist or incorrect signature: ISPICKVAL(Schema.SObjectField, String) at line 3 column 5. I've been banging my head against my desk for the better part of half an hour trying to figure this out. please help.

 

trigger sendEmailAlert on Opportunity (after insert, after update) {

if (ISPICKVAL(opportunity.stagename, 'Send Rebecca Request')){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

Attachment[] queryAttachment = [select Name from Attachment where Parentid=:'accountId' order by CreatedDate DESC];

Messaging.EmailFileAttachment[] allAttachments = new Messaging.EmailFileAttachment[queryAttachment.size()];
        
        
        for(integer i=0;i<queryAttachment.size();i++)
        {
        
        
            Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
            fileAttachment.setBody(queryAttachment[i].Body);
        
        
        
            fileAttachment.setFileName(queryAttachment[i].Name);
            allAttachments[i] =  fileAttachment;
        } 

 

 

 

 

 

desidskdesidsk

ISPICKVAL is function that can be used only in formula fields or validation rules

 

Thanks,

Daya

dreamrealdreamreal

Thank you!

 

Do you know what I could use instead then?

hisrinuhisrinu

You can directly write like 

if(opportunity.stagename == 'Send Rebecca Request'){
// Your code block here
}
dreamrealdreamreal

I tried this but got the following error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String at line 4 column 5. Any ideas on how to rectify the situation?