Writing script to prevent attachments over 35MB from syncing from Salesforce to ADO/JIRA

Originally asked by Kaleigh Garcia on 08 April 2024 (original question)


Hello! I’m new to writing Groovy and looking for assistance in writing some script in preventing attachments over 35MB from being able to sync bidirectionally from Salesforce to ADO/Jira. We receive a Bad Gateway Error that makes our Console completely inaccessible when a large attachment sync amongst one of our connections. Any guidance is appreciated.


Answer by Andrea Mura on 24 April 2024

Hi!

this is the way I filter outgoing attachments on the Salesforce side towards Jira, I hope it’s useful to you!

def remoteAttachments = entity.attachments.findAll { attachment ->
         replica.filename = attachment.filename
         String fileName= attachment.getFilename()
         replica.estensione = fileName
attachment
}
 
//The max size of the attachments in bytes. 1MB = 1.000.000 bytes
def maxFileSize = 300000000
def refacturedList = []
for(file in remoteAttachments){
    if(file.filesize <= maxFileSize){
        refacturedList.add(file)
    }
}
replica.attachments = refacturedList