You need to sign in to do that
Don't have an account?
Robert Lange 6
Determine invoice name
I have the following trigger that inserts an Invoice as a related object to the Contact. The Invoice has a number field that is auto-generated. Is there a way to code this so that the each Invoice will have the name "Invoice" plus it's number (0001, 0002, etc.)?
trigger contactGenInvoice on Contact (after insert, after update) {
List<Invoice__c> invoiceList = new List<Invoice__c>();
for (Contact con : Trigger.new) {
if (con.Status__c == 'Inactive') {
Invoice__c i = new Invoice__c();
i.Name = 'Invoice ';
i.Date__c = System.today();
i.Amount__c = 100;
i.ContactId__c = con.Id;
invoiceList.add(i);
}
insert invoiceList;
}
}
trigger contactGenInvoice on Contact (after insert, after update) {
List<Invoice__c> invoiceList = new List<Invoice__c>();
for (Contact con : Trigger.new) {
if (con.Status__c == 'Inactive') {
Invoice__c i = new Invoice__c();
i.Name = 'Invoice ';
i.Date__c = System.today();
i.Amount__c = 100;
i.ContactId__c = con.Id;
invoiceList.add(i);
}
insert invoiceList;
}
}
You can try using workflow to update Invoice Name with Name + AutoNumber.
If "Criteria:- ContactId__r.Status__c ='Inactive'" is true then make field update on Name field.
Formula Value: Name&' '&Auto_Number__c.
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar