You need to sign in to do that
Don't have an account?
Rachel Linder
Receiving - Unexpected Token: 'List' Error on Apex Trigger
I am looking to create a trigger on attachments on the opportunity object. I want the trigger to look at the attachments area and if it sees attachment fill in the checkbox on the opportuntity for has attachments. This is what I have but I am receiving an error for line item 14 that says Unexpected Token: 'List". What does this mean and what would my fix be?
//*************************************************************************************
//Name : Does Opportunity Have Attachments
//Description : Completes the Attachments checkbox on opportunity to signify that
// there are attachments on this opportunity
//Created By : Rachel Linder (rlinder@insightinvestments.com)
//************************Version Updates**********************************************
//
//Version Updated Date Updated By Update Comments
//1 10/22/2014 Rachel Linder Initial creation of trigger
//
//*************************************************************************************
trigger AttachmentTrigger on Attachment (before insert) {
List opportunityList = new List();
Set opptyIds = new Set()
for(Attachment : trigger.New){
//Check if added attachment is related to the Opportunity or not
if(att.OpportunityID.getSobjectType() == Opportunity.SobjectType){
opptyIds.add(att.OpportunityID:);
}
}
opportunityList = [select id, Has_attachments__c from Opportunity where id in : opptyids];
if(opportunityList!=null && opportunityList.size()>0){
for(Opportunity oppty : opportunityList){
oppty.Has_attachments__c = true;
}
update opportunityList;
}
}
Thanks.
//*************************************************************************************
//Name : Does Opportunity Have Attachments
//Description : Completes the Attachments checkbox on opportunity to signify that
// there are attachments on this opportunity
//Created By : Rachel Linder (rlinder@insightinvestments.com)
//************************Version Updates**********************************************
//
//Version Updated Date Updated By Update Comments
//1 10/22/2014 Rachel Linder Initial creation of trigger
//
//*************************************************************************************
trigger AttachmentTrigger on Attachment (before insert) {
List opportunityList = new List();
Set opptyIds = new Set()
for(Attachment : trigger.New){
//Check if added attachment is related to the Opportunity or not
if(att.OpportunityID.getSobjectType() == Opportunity.SobjectType){
opptyIds.add(att.OpportunityID:);
}
}
opportunityList = [select id, Has_attachments__c from Opportunity where id in : opptyids];
if(opportunityList!=null && opportunityList.size()>0){
for(Opportunity oppty : opportunityList){
oppty.Has_attachments__c = true;
}
update opportunityList;
}
}
Thanks.
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
All Answers
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
I am in sandbox and trying to save the trigger above but I am getting an error on line 15 that says: "Error: Compile Error: expecting a semi-colon, found 'opptyIds' at line 15 column 12".
Here is the code for the trigger. Line 15 is the line that says Set opptyIds - new Set()
//*************************************************************************************
//Name : Does Opportunity Have Attachments
//Description : Completes the Attachments checkbox on opportunity to signify that
// there are attachments on this opportunity
//Created By : Rachel Linder (rlinder@insightinvestments.com)
//************************Version Updates**********************************************
//
//Version Updated Date Updated By Update Comments
//1 10/22/2014 Rachel Linder Initial creation of trigger
//
//*************************************************************************************
trigger AttachmentTrigger on Attachment (before insert) {
List<Opportunity> opportunityList = new List<Opportunity>();
Set opptyIds = new Set()
for(Attachment : trigger.New){
//Check if added attachment is related to the Opportunity or not
if(att.OpportunityID.getSobjectType() == Opportunity.SobjectType){
opptyIds.add(att.OpportunityID:);
}
}
opportunityList = [select id, Has_attachments__c from Opportunity where id in : opptyids];
if(opportunityList!=null && opportunityList.size()>0){
for(Opportunity oppty : opportunityList){
oppty.Has_attachments__c = true;
}
update opportunityList;
}
}