You need to sign in to do that
Don't have an account?

Receiving Error "expecting semi-colon received oppty ids"
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 15 that says "expecting semi-colon received opptyids".. 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.
I have cleaned up your code. You had a few typos here and there. Also, "OpportunityID" does not exist on Attachment object, so I used ParentId insted. Plus when I tested it id frew an error because of "before Insert" trigger type so I switched it ot "after Insert". Test is and see if it works for you. Good luck.
trigger AttachmentTrigger on Attachment (after insert) {
List<Opportunity > opportunityList = new List<Opportunity>();
Set<ID> opptyIds = new Set<ID>();
for(Attachment att: trigger.New){
//Check if added attachment is related to the Opportunity or not
if(att.ParentId.getSobjectType() == Opportunity.SobjectType){
opptyIds.add(att.ParentId);
}
}
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;
}
}
All Answers
Set opptyIds = new Set();
I have cleaned up your code. You had a few typos here and there. Also, "OpportunityID" does not exist on Attachment object, so I used ParentId insted. Plus when I tested it id frew an error because of "before Insert" trigger type so I switched it ot "after Insert". Test is and see if it works for you. Good luck.
trigger AttachmentTrigger on Attachment (after insert) {
List<Opportunity > opportunityList = new List<Opportunity>();
Set<ID> opptyIds = new Set<ID>();
for(Attachment att: trigger.New){
//Check if added attachment is related to the Opportunity or not
if(att.ParentId.getSobjectType() == Opportunity.SobjectType){
opptyIds.add(att.ParentId);
}
}
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;
}
}