function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robert Lange 6Robert 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 : {
        if (con.Status__c == 'Inactive') {

            Invoice__c i = new Invoice__c();

            i.Name = 'Invoice ';
            i.Date__c =;
            i.Amount__c = 100;
            i.ContactId__c = con.Id;

        insert invoiceList;
VinayVinay (Salesforce Developers) 
Hi Robert,

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.

Vinay Kumar