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
Jessica RectorJessica Rector 

Apex Help Needed for New Record

Thank you in advance for any assistance!  Within a specific quote record type, we "look up" to an existing custom object record and when the quote is closed "won", a new custom object record is created.  Let me paint the picture.  I create a new 'conversion" opportunity and then a "conversion" quote where I'm able to look up to machine number "1234".  The machine number field is an auto number that issues in sequence.  When I close a new conversion quote as won, a few things happen.  First, the existing machine (in this example "1234" switches to a "Converted" record type with matching page layout that locks down all fields and shows the converted date.  Second, the new machine record is created with updated specs from the quote.  The machine number is whatever is next in the sequence is and this is where I'm struggling.  

I need for the new record to reflect the old machine "1234" and then to show "C-1" for conversion 1.  If the old machine was "1234 C-1" then new one should be "1234 C-2".  I hope that this makes sense and that someone can point me in the right direction.
 

Thanks again,
 

Jessica

Jaap BranderhorstJaap Branderhorst
So let me try to understand this. You have a custom object called Machine with an auto-number field on it with the format {1234}. When you convert an opportunity the record type of the Machine object changes to 'converted' effectively locking down input via the UI (but not via the API!). Then a new machine record is created and the auto-number format should be {1234}-C-{1} where the {1234} contains the auto-number of the old machine.

Unfortunately this is not possible with an auto-number field. Best way forward IMHO is to have an extra field on the Machine custom object called (for example) 'conversion number' that defaults to 0 and another formula field called (for example again) 'complete machine number' containing <auto-number of the old machine> + " C-" + <conversion number>. Now you create a lightning process that triggers on conversion of the quote. It then creates a new machine record and in the create action you set the machine number of the 'old' machine and the conversion number. You also set the conversion number on the new machine record to 1 via a formula. Good luck!
Jessica RectorJessica Rector
Thank you Jaap!  When a "new machine" quote is won, the auto number works for creating the new machine record and needs to stay that way.  The "conversion" quote won creates essentially a new machine record and needs to stay the same, but we need to hijack the original machine number and add the C-1.  I appreciate your suggestion and feel like it is something I can click my way through, but the ideal situation would be APEX that would capture that original number and add the C-1 in the original field.  

I'm not sure if I need a new page layout/record type for the machine object beyond the old machine/converted one I've done.  Thank you again for your input...it might be what I end up going if I can't find another way.
Jaap BranderhorstJaap Branderhorst
Hi Jessica, I always advice Salesforce customers and ISV's to use our declarative features if possible and not use code. It's better maintainable and in the end much less work. My suggestion was not to delete the auto number but merely to have a couple of new fields to implement your requirements. Regards / met vriendelijke groet, Jaap Branderhorst Senior ISV Technical Evangelist Salesforce.com Apologies for typos and abbreviations.