You need to sign in to do that
Don't have an account?
Kim Wojno
Issue with Conditional Apex Trigger
I am looking to put in a trigger that will automatically attach a pdf contract from a VF page to the opportunity. Below is what I have (via http://jungleeforce.wordpress.com/2013/05/08/generate-a-pdf-and-attach-it-to-record-from-a-trigger-in-salesforce/) and modified. However I want to put in an if statement but I keep getting the error "Concrete SObject." The if stament I am trying to put in:
if(opportunity.stageName == 'Sent Contract for Review' && opportunity.Contract_Attached__c == False)
Any help here? I am referencing the opportunity ID in the list but need a way to make it reference the opportunity itself with only one action being done.
trigger GenerateContract on Opportunity (after update, after insert) {
list<id> opportunityId = new list<id>();
for(id opportunity: trigger.newMap.keySet()){
opportunityId.add(opportunity);
}
AccountTriggerController.addPDFAttach(userInfo.getSessionId(), opportunityId);
if(opportunity.stageName == 'Sent Contract for Review' && opportunity.Contract_Attached__c == False)
Any help here? I am referencing the opportunity ID in the list but need a way to make it reference the opportunity itself with only one action being done.
trigger GenerateContract on Opportunity (after update, after insert) {
list<id> opportunityId = new list<id>();
for(id opportunity: trigger.newMap.keySet()){
opportunityId.add(opportunity);
}
AccountTriggerController.addPDFAttach(userInfo.getSessionId(), opportunityId);
All Answers
You cannot use "opportuniity" as a variable for your FOR loop, as it is a reserved word for the opportunity sObject. Please select a different variable. Something like:
for(id oppId: trigger.newMap.keySet()){
if(oppId.stageName == 'Sent Contract for Review' && oppId.Contract_Attached__c == False){
opportunityId.add(opportunity);
}
}
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
but I am not getting an error that is dones't recongize (opportunity) on line 6.
Once you are done with modification for class.Try below code :-
If this helps,please mark it as best answer to help others :)
I put in place the below code but am now getting "Error: Compile Error: AND operator can only be applied to Boolean expressions at line 5 column 53"