+ Start a Discussion
Sean NolansSean Nolans 

Error: Compile Error: Unexpected token '.'. at line

No way in SF to update worklow (field) when a file is attached to a record in using native SF
So using a trigger - I took an example from the forums 

I am trying to say when the attachment contains signed as it will be Esigned 

But I am getting this 
Error: Compile Error: Unexpected token '.'. at line 11 column 44

This is what I have 

trigger TestAttachmentCheck on Attachment (after insert, after update, after delete, after undelete) {
    List <Account> AccountList = new List<Account>();
     List <Account> AccountListToUdpdate = new List<Account>();
    Set <Id> AccountIds = new Set <Id>();
    
    if(trigger.isInsert || trigger.isUpdate)
    {
    for(Attachment attach : trigger.New){
         //Check if added attachment is related to Account or not
         if(attach.ParentId.getSobjectType() == Account.SobjectType){
            if(string.valueOf(attach.Name)).contains('signed'))
               AccountIds.add(attach.ParentId);
         }
    }
    }
    
    if(trigger.isDelete || trigger.isUndelete)
    {
    for(Attachment attach : trigger.old){
         //Check if added attachment is related to Account or not
         if(attach.ParentId.getSobjectType() == Account.SobjectType){
            if(string.valueOf(attach.Name)).startswith('.xls'))
               AccountIds.add(attach.ParentId);
         }
    }
    }
    
    AccountList = [select id, CIN_Uploaded__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
    
           Account accountToUpdate = new accountToUpdate();
           AccountToUpdate.Id = account.Id;
           AccountToUpdate.CIN_Uploaded__c  = true;
           AccountListToUdpdate.add(accountToUpdate);
                
    }
       
        update AccountListToUdpdate;
}
Best Answer chosen by Sean Nolans
Raj VakatiRaj Vakati
Try this
 
trigger TestAttachmentCheck on Attachment (after insert, after update, after delete, after undelete) {
    List <Account> AccountList = new List<Account>();
    List <Account> AccountListToUdpdate = new List<Account>();
    Set <Id> AccountIds = new Set <Id>();
    
    if(trigger.isInsert || trigger.isUpdate)
    {
        for(Attachment attach : trigger.New){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
    if(trigger.isDelete || trigger.isUndelete)
    {
        for(Attachment attach : trigger.old){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
List<Account> AccountList = [select id, Authorised_Contact__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
        // Add New account()
        Account accountToUpdate = new Account();
        AccountToUpdate.Id = account.Id;
        AccountToUpdate.Authorised_Contact__c  = true;
        AccountListToUdpdate.add(accountToUpdate);
        
    }
    
If(AccountListToUdpdate.size()>0){
    update AccountListToUdpdate;
}
}

 

All Answers

Raj VakatiRaj Vakati
Try this code
 
trigger TestAttachmentCheck on Attachment (after insert, after update, after delete, after undelete) {
    List <Account> AccountList = new List<Account>();
    List <Account> AccountListToUdpdate = new List<Account>();
    Set <Id> AccountIds = new Set <Id>();
    
    if(trigger.isInsert || trigger.isUpdate)
    {
        for(Attachment attach : trigger.New){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
    if(trigger.isDelete || trigger.isUndelete)
    {
        for(Attachment attach : trigger.old){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).startswith('.xls'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
    AccountList = [select id, CIN_Uploaded__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
        
        Account accountToUpdate = new accountToUpdate();
        AccountToUpdate.Id = account.Id;
        AccountToUpdate.CIN_Uploaded__c  = true;
        AccountListToUdpdate.add(accountToUpdate);
        
    }
    
    update AccountListToUdpdate;
}

 
Sean NolansSean Nolans
Hi @rav j


Thanks for that i have gotten past that error 

I have now changed the custom field names (shouldnt matter) BUT

Iam getting this 


Error: Compile Error: Invalid type: AccountToUpdate at line 31 column 35




trigger TestAttachmentCheck on Attachment (after insert, after update, after delete, after undelete) {
    List <Account> AccountList = new List<Account>();
    List <Account> AccountListToUdpdate = new List<Account>();
    Set <Id> AccountIds = new Set <Id>();
    
    if(trigger.isInsert || trigger.isUpdate)
    {
        for(Attachment attach : trigger.New){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
    if(trigger.isDelete || trigger.isUndelete)
    {
        for(Attachment attach : trigger.old){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
    AccountList = [select id, Authorised_Contact__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
        
        Account accountToUpdate = new AccountToUpdate();
        AccountToUpdate.Id = account.Id;
        AccountToUpdate.Authorised_Contact__c  = true;
        AccountListToUdpdate.add(accountToUpdate);
        
    }
    
    update AccountListToUdpdate;
}


User-added image
v varaprasadv varaprasad
Hi ,

Above code is perfect just change below line : 

Try This : 



AccountList = [select id, Authorised_Contact__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
        // Add New account()
        Account accountToUpdate = new Account();
        AccountToUpdate.Id = account.Id;
        AccountToUpdate.Authorised_Contact__c  = true;
        AccountListToUdpdate.add(accountToUpdate);
        
    }
    
    update AccountListToUdpdate;

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/

Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1

 
Raj VakatiRaj Vakati
this is the corrct 
 
List<Account > List = [select id, Authorised_Contact__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
        // Add New account()
        Account accountToUpdate = new Account();
        AccountToUpdate.Id = account.Id;
        AccountToUpdate.Authorised_Contact__c  = true;
        AccountListToUdpdate.add(accountToUpdate);
        
    }
    
If(AccountListToUdpdate.size()>0){
    update AccountListToUdpdate;
}


 
Sean NolansSean Nolans
Hey

I think I am almost there with your help 

But still hitting errors

With this 

trigger TestAttachmentCheck on Attachment (after insert, after update, after delete, after undelete) {
    List <Account> AccountList = new List<Account>();
    List <Account> AccountListToUdpdate = new List<Account>();
    Set <Id> AccountIds = new Set <Id>();
    
    if(trigger.isInsert || trigger.isUpdate)
    {
        for(Attachment attach : trigger.New){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
    if(trigger.isDelete || trigger.isUndelete)
    {
        for(Attachment attach : trigger.old){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
AccountList = [select id, Authorised_Contact__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
        // Add New account()
        Account accountToUpdate = new Account();
        AccountToUpdate.Id = account.Id;
        AccountToUpdate.Authorised_Contact__c  = true;
        AccountListToUdpdate.add(accountToUpdate);
        
    }
    
If(AccountListToUdpdate.size()>0){
    update AccountListToUdpdate;
}
}

I am now getting this 

Error: Compile Error: Incorrect SObject type: Attachment should be Account at line -1 column -1


User-added image
Raj VakatiRaj Vakati
Try this
 
trigger TestAttachmentCheck on Attachment (after insert, after update, after delete, after undelete) {
    List <Account> AccountList = new List<Account>();
    List <Account> AccountListToUdpdate = new List<Account>();
    Set <Id> AccountIds = new Set <Id>();
    
    if(trigger.isInsert || trigger.isUpdate)
    {
        for(Attachment attach : trigger.New){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
    if(trigger.isDelete || trigger.isUndelete)
    {
        for(Attachment attach : trigger.old){
            //Check if added attachment is related to Account or not
            if(attach.ParentId.getSobjectType() == Account.SobjectType){
                if(string.valueOf(attach.Name).contains('signed'))
                    AccountIds.add(attach.ParentId);
            }
        }
    }
    
List<Account> AccountList = [select id, Authorised_Contact__c from Account where id in : AccountIds];
    for(Account Account : AccountList){    
        // Add New account()
        Account accountToUpdate = new Account();
        AccountToUpdate.Id = account.Id;
        AccountToUpdate.Authorised_Contact__c  = true;
        AccountListToUdpdate.add(accountToUpdate);
        
    }
    
If(AccountListToUdpdate.size()>0){
    update AccountListToUdpdate;
}
}

 
This was selected as the best answer
Sean NolansSean Nolans
FYI
This is a person accounts instance - shouldnt matter thugh - right ?

I need to remove "List<Account>" from line 28  in order to get past 
Compile Error: Duplicate field: AccountList at line 28 column 15

when i do that I am still getting 

Error: Compile Error: Incorrect SObject type: Attachment should be Account at line -1 column -1

User-added image

User-added image

The -1 part is v strange ?

 
Raj VakatiRaj Vakati
then change to PersonalAccount