Skip to main content
Nintex Community Menu Bar

I’m looking to build some logic that saves related items to the database all in the same save action sequence, and rolls back inserts if anything went wrong.

To this end, I’d like to use the SKUID Temporary IDs to relate items together via APEX code, so I can create and relate these things all together with a trigger on insert by querying for the SKUID Temporary ID, and then relate the related objects based on their Salesforce IDs after finding them via the SKUID IDs.

In order for this to work, the SKUID Temporary IDs that get generated would need to be unique not just to the local instance of the page, but also to the entire database. Is this the case? Are SKUID Temporary IDs unique to all other SKUID Temporary IDs ever created, or are they only unique to the local instance of the page? If they are unique only to the local instance of the page, is there any way I could use them to create an ID that is unique to the entire database?

----

Further details of proposed design for context:

I’m inserting an Invoice and Invoice Lines via a wizard where Step 1 is to create the Invoice and Step 2 is to create the Invoice Lines. Normally I’d save the invoice after Step 1 is complete so I can then relate the Invoice Lines to the Salesforce ID of the Invoice, but if I Save Step 1 and then close the wizard (or my browser crashes), I get an “orphan Invoice” where it’s just an invoice that got saved that has no lines on it.

If instead I only saved the Invoice and the Invoice Lines all at the same time and rolled back the save if anything failed, then I won’t have to worry about the possibility of an orphan Invoice, but in order to do this I need to relate the objects together, and can’t get the Salesforce ID of the Invoice until it is saved.

If I can use a unique ID to relate these objects together, (SKUID temporary ID?) and insert the Invoice with a new field (SKID__c) where I populate that field with the unique ID, then when inserting Invoice Lines I populate their Invoice_SKID__c with that temporary ID and in APEX have it find the Invoice Salesforce ID and relate the Invoice Lines to the Invoice via Lookup with the Salesforce ID, I should be able to insert all at the same time and maintain relationships properly.

Hmmm … not sure you need to go to all that trouble. Skuid Save has functionality to revert all changes on error.


Further, the Skuid IDs aren’t stored anywhere and are unique to each session. So you can refresh your page and the same records would have different Skuid IDs.


Skuid IDs are always entirely unique. At least this is my understanding and would be quite surprised otherwise. 😉


As for relating Line Items, you can do this prior to save using the temp Skuid ID of the Invoice. The one thing I’m not certain about is the APEX bit. Fairly certain that any error in APEX would cause the save to fail and everything would be fine.


Hope this helps. Maybe I missed why you felt you need to use temp skuid temp IDs in Apex. Lemeno 😉


Mark, Skuid already enables this out of the box — you don’t need to write Apex to do this.

All you have to do to achieve this is to have a “Field from another Model” Condition on your Invoice Lines model that references the Id of the Invoice Model, and then have your Save button at the end of Step 2 of the wizard save both Models, and check the “Rollback entire save if any errors occur” checkbox that is available on the Save action. Skuid automatically handles linking the new Invoice Lines to the Invoice once the Invoice is saved — and if there is any error saving the Invoice Lines, all of the save operations will be rolled back — the Invoice will not be saved, and none of the Invoice Lines will be saved. This linkage of new Invoice Lines to their parent Invoice, once created, is done server-side by Skuid. 


Thanks Zach,


We didn’t realize this was possible, but this design is absolutely perfect.


One more question on this topic. If I need to upload an attachment to the record that is pending save to Salesforce – is it possible to do that without first saving the record?


Currently no. The record must be saved before you can upload an attachment.


There is a way to do it, but it’s in the hack category of solutions. Would lead to orphaned attachments when the unsaved new record is cancel/abandoned.


There is a way to never get orphaned attachments, but this solution would not be tenable.