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
Adam08Adam08 

Attachments Trigger

Hi,

 

I have a trigger that updates a field in a custom object (record detail).

The trigger works fine (based on the file size being greater than 0 but i'm trying to add in another condition based on the file type being an excel file.

 

trigger updatemdf on Attachment (after insert) 
            {
                        List<MDF__c> co = [select id, Leads_uploaded__c from mdf__c where id =: Trigger.New[0].ParentId];
                        if (co.Name.endsWith('.xls') && (co.size()>0))
                        {
                                    co[0].leads_uploaded__c = true;
                                    update co;
                        }                                                                    
            }

 error messgae i'm getting at line 4 is:

'Save error: Initial term of field expression must be a concrete SObject: LIST<MDF__c> 

 

Any ideas?

 

Thanks

Rahul SharmaRahul Sharma

try this:

 

trigger updatemdf on Attachment (after insert) 
            {
                        List<MDF__c> co = [select id, Leads_uploaded__c from mdf__c where id =: Trigger.New[0].ParentId];
                        if (co[0].Name.endsWith('.xls') && (co.size()>0))
                        {
                                    co[0].leads_uploaded__c = true;
                                    update co;
                        }                                                                    
            }

 

Adam08Adam08

Thanks Rahul,

 

Although that seems to be trying to run the trigger on the Name of the custom object.

 

What i want is to trigger on the file name of the attachment associated with the custom object.

Rahul SharmaRahul Sharma

Hi Adam018,

 

I guess you dont want bulk updates,

and here problem is you want to update a boolean field of the object if the filetype is .xls

If its the case, then change your code to:

trigger updatemdf on Attachment (after insert) 
            {
                        List<MDF__c> co = [select id, Leads_uploaded__c from mdf__c where id =: Trigger.New[0].ParentId];
                        if (Trigger.New[0].Name.endsWith('.xls') && (co.size()>0))
                        {
                                    co[0].leads_uploaded__c = true;
                                    update co;
                        }                                                                    
            }

 Hope it helps.