I have a need to create a new record from an existing one on a Lightning page, but selecting specific fields only, not all (it's about 50/50 of used/unused fields), and adding some new values not on the existing one. This option to create will only apply to certain conditions being met on the existing record, so I can't use a standard button/link as that isn't conditional. The new record will be the same object type, but a different RecordType.
I was therefore thinking of an LWC which is displayed based on the condition being met on the record displayed, with a button to create the new record.
What is the best way to create the new record?
- Use an Apex class? I pass the current record Id to it and do a query to get all the necessary fields, create it and on successful create, return to display this new one?
- Use createRecord in the LWC? If I did this, would I have to import all the fields required off the original record in order to pass them into the new one?
- Navigate to the create page of the record using NavigationMixin.Navigate, passing the values from the existing one in the 'defaultFieldValues'? Again, how do I access these values from the existing one - by importing all these fields individually (ie. import STATUS_FIELD from "@salesforce/schema/myObject__c.Status__c"; for each field I need)?