You need to sign in to do that
Don't have an account?
Trif Cristian 7
how can i transform this trigger in a batch class?
Hello, I'm trying to convert my trigger to a batch class. Can anyone help me with this one, I would much appreciate:
trigger SetTitleToAttachment on Attachment (before insert) { //store the id of the WO related to the attachment List<String> woIDs= new List<String>(); for (Attachment orderRec : Trigger.new) { woIDs.add(orderRec.ParentID); } System.Debug('>>>>'+woIDs); //store the work order(s) where the ID in woIDs Map<String, SVMXC__Service_Order__c > woByIds= new Map<String, SVMXC__Service_Order__c >([ SELECT Id, Name, SVMX_PS_Ship_To_Name__c, SVMXC__Order_Type__c, SerialNumberIP__c FROM SVMXC__Service_Order__c WHERE Id =: woIDs ]); //change the name of the attachment System.debug('woByIds'+ woByIds); for(Attachment a: Trigger.new){ SVMXC__Service_Order__c workorder = woByIds.get(a.ParentId); System.debug('workorder '+ workorder ); if(workorder != null){ if(a.Name.startsWith('SIG_Work_Order_Service__Reports')){ a.Name = 'SR'+ '_'+ date.today().format()+ '_'+workorder.SVMX_PS_Ship_To_Name__c+ '_' + workorder.Name+ '_'+ workorder.SVMXC__Order_Type__c+'_'+ workorder.SerialNumberIP__c +'.pdf'; } else if (a.Name.startsWith('SIG_HandoverCheckList_Customer_To_SIG_Report')){ a.Name = 'Handover Customer To SIG' +'.pdf'; } else if (a.Name.startsWith('SIG_HandoverCheckList_SIG_To_Customer')){ a.Name = 'Handover SIG_To_Customer'+'.pdf'; } else if (a.Name.startsWith('SIG_Work_Order_Service')){ a.Name = 'SR'+ '_'+ date.today().format()+ '_'+workorder.SVMX_PS_Ship_To_Name__c+ '_' + workorder.Name+ '_'+ workorder.SVMXC__Order_Type__c+'_'+ workorder.SerialNumberIP__c+'.pdf' ; } } } }
Try the below class:
Thanks,
Maharajan.C
Hi Maharajan,
It works! Thanks bro :).
I changed a little bit the code, like this:
But now I would need somehow to increment this attachments by 1 everytime it is changed. It is possible to do that?
You see? They are the same and I would need something like:
SR1_6/16/2020_GreenSpot
SR2_6/16/2020_GreenSpot
SR3_6/16/2020_Greenspot
How can i increment this everytime a new attachment is updated... any idea?
Thanks!