You need to sign in to do that
Don't have an account?
Cris9931
trigger to update attachment name
Hello, I want to update my attachments name after they are created. This works but the name of the Work Order(custom object) is not automatically. This is my attachments and you can see Related to : WO-0003061.
my trigger, it works if i hard code the name:
trigger SetTitleToAttachment on Attachment (before insert) { for(Attachment a: Trigger.new){ if(a.Name.startsWith('SIG_PM_Work_Order_Service_Report')){ a.Name = 'Work Order name dynamically '; } else if (a.Name.startsWith('SIG_HandoverCheckList_Customer_To_SIG_Report')){ a.Name = 'ServiceReport.pdf'; } } }
I want to on the line a.Name = 'Work Order name dynamically '; to be instead of this string to be the name WO-0003061. How can i do this?
Please help. I would appreciate a lot :)
Being relatedTo the field you have under that label for example a.RelatedTo__r.Name
Check that out.
If it helps please like and mark as correct as it may help others.
If it does not work please use a system.debug(a.RelatedTo__r.Name) to check if you can see that field, also system.debug(a.RelatedTo__c) to check if you at least have the reference.
HI Agustin,
Nope... I tried with RelatedTo.. in fact it is ParentID cause its a reference
my code works fine like this:
Do you know how can I make an like an autonumber in this trigger?
Integer i=1;
for example where a.Name = 'Handover Customer To SIG'+ '-'+ i +'.pdf';
so everytime should be incremented by one so the result to be:
Handover Customer To SIG -1.pdf
Handover Customer To SIG -2.pdf..
Integer i=1;
a.Name = 'Handover Customer To SIG'+ '-'+ i +'.pdf';
and before the closing } of the for you put i++; to increment the counter by 1.
I created two attachments.. not working..
my code: