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
Rachel LinderRachel 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.
Best Answer chosen by Rachel Linder
Balaji BondarBalaji Bondar
update below code:
List<Opportunity> opportunityList = new List<Opportunity>();
Important :
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

Balaji BondarBalaji Bondar
update below code:
List<Opportunity> opportunityList = new List<Opportunity>();
Important :
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.
This was selected as the best answer
Rachel LinderRachel Linder
Thank you. I updated that line and now on line 15 it says expecting a semmi-colon, found 'opptyIds".
Rachel LinderRachel Linder
Is there anyone who can help with the error above for line 15? Thanks.
Rachel LinderRachel Linder
Hi All,
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;
    }
}