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
Gary Payne 9Gary Payne 9 

How to create a new Asset record for a junction object Case Asset when the Case Status is Cancelled?

The Case requirement is to allow multiple Asset records per Case and require at least one Asset record in order to save a Case record when the Status is "Cancelled", "Saved", or "Closed".  The Account record will already have Asset records tied to it.  I created a junction object called Case Asset  to allow multiple Asset records per Case record. What is needed to force the user to create Case Asset records before saving a Case record when the Status is "Cancelled", "Saved", or "Closed". ?
SalesFORCE_enFORCErSalesFORCE_enFORCEr
You dont need to create a junction object, you can just create a lookup to Case on Asset object and then write a trigger on case which will check the number of Asset records while saving the Case record and if the count of asset record is 0 then it will throw an error message.
Gary Payne 9Gary Payne 9
So if I'm working on a Case record, how do I create multiple Asset records associated to the Case before saving the Case?  Can you provide the Apex Trigger code needed to perform your suggested solution?
SalesFORCE_enFORCErSalesFORCE_enFORCEr
So, just to be clear. Your case is already created and you want the user to create Asset record before changing the status to something else right?