Skip to main content
Hi all,

 

I'm trying to export attachments from SalesForce naming all files with data present in their parent record.

 

I'm talking about pictures that we collect on service appointments records, and I'm talking about 2/300 pictures a day.

 

My file should be named like this:

 

parent_record_number__C-ParentRecord_Date-Parent_Record_ID.jpg.

 

I'm trying to do that with Skyvia but it seems there's no way to rename the attachment. 

 

Do you have any idea/suggestion on how to do that? 

 

Thank you.

 

 
1 个回答
  1. 2019年11月28日 13:55
    Hi Massimiliano Ciarrocca,

     

    * The logic here is to let the insert happen, and in after insert trigger does a DML to update the name of attachment with that of parent's Name.

     

     

    trigger renameAttachment on Attachment (after insert) 

        {

            List<Attachment> toBeUpdatedAttachment = new List<Attachment>();

            for(Attachment objAttachment : [SELECT id,Name,ParentId,Parent.Name FROM Attachment WHERE Id IN:Trigger.new])

            {

                       objAttachment.Name = objAttachment.Parent.Name;

                       toBeUpdatedAttachment.add(objAttachment);

            }

          update toBeUpdatedAttachment;

        }

     

    * Please take reference from below links:

     

       https://developer.salesforce.com/forums/?id=906F0000000QtjtIAC

     

       https://help.salesforce.com/articleView?id=000326721&language=en_US&type=1&mode=1 (https://help.salesforce.com/articleView?id=000326721&language=en_US&type=1&mode=1)

     

       https://salesforce.stackexchange.com/questions/218666/rename-attachment-name

     

    I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

     

    Thanks and Regards,

     

    Ajay Dubedi

     

    www.ajaydubedi.com
0/9000