+ Start a Discussion
dreamrealdreamreal 

How to obtain value in Stage field of an Opportunity

I am attempting to write a trigger that fires at a specific stage of a opportunity. I feel like this is really stupid but salesforcce isnt allowing me to refer to the current stage as Opportunity.stagename

What am I doing wrong

Venkat PolisettVenkat Polisett

Please post you trigger code.


dreamreal wrote:

I am attempting to write a trigger that fires at a specific stage of a opportunity. I feel like this is really stupid but salesforcce isnt allowing me to refer to the current stage as Opportunity.stagename

What am I doing wrong


 

dreamrealdreamreal

 

trigger sendCaseEmailAlerts on Case (after insert, after update) {


if (Opportunity.stage == 'Send Rebecca Request') {

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

Attachment[] queryAttachment = [select Body, Id, Name, ContentType from Attachment where Parentid=:'accountId'];

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;
        } 

mail.setFileAttachments(allAttachments);
mail.setTemplate(00X30000001Dbqp);
mail.setTargetObjectID(003Q000000BQ5Bw);


}
}

 

 

Venkat PolisettVenkat Polisett

//Should be

stageName 

 

You cannot directly use Opportunity in your trigger. Triggers expose Trigger.new, Trigger.old, Trigger.newMap and Trigger.oldMap depending on before and after operations.

 

Please read the section on triggers in Force.com Apex Developers Guide.

 


dreamreal wrote:

 

 

trigger sendCaseEmailAlerts on Case (after insert, after update) {


if (Opportunity.stage == 'Send Rebecca Request') {

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

Attachment[] queryAttachment = [select Body, Id, Name, ContentType from Attachment where Parentid=:'accountId'];

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;
        } 

mail.setFileAttachments(allAttachments);
mail.setTemplate(00X30000001Dbqp);
mail.setTargetObjectID(003Q000000BQ5Bw);


}
}