Fist pump time!!! Got my crazy cloning snippet done in way less time expected.

  • 4
  • Praise
  • Updated 4 years ago
Praise to the Skuid folks!!!

Your app allows me to do so much in such little time where it would otherwise cost me and my client 10X more without it. The following was quoted to take 25-35 hours in APEX. Probably more as I learned about some additional hiccups during the process. Always impressed with what's possible.

My snippet clones a 9 object data set where approx. 30-50 records are being queried using model Clone property "Yes, Always". So now when the factory manager submits a production order for products of any kind, the template (9 object record set) of this product (the Master record type), is cloned, set to record type "Production" and linked to the original Master record using a custom formula field called GhostRecordId prior to saving the cloned record.

AWESOME!!!!! Look at how little code is required to do this!!!!!

var params = arguments[0],
	$ = skuid.$,
	prodProductions = skuid.$M('POLineProductProductions'),
	prodCount =,
	cloneProductCode = skuid.$M('cloneProductCode'),
	models = [],
	dfd = $.Deferred();
    $.blockUI({message: 'Placing order'});
    function queryCloneModels(prodIndex){
        // query more clone models once per product production
        $.blockUI({message: 'Placing order on product production ' + prodIndex + '/' + prodCount});
                // loop through all models and rows to set Master with GhostRecord
                       model.updateRow(row,{Master__c: row.GhostRecordId__c});
                        prodProductionRow = prodProductions.getFirstRow();
                        cloneProductCodeRow = cloneProductCode.getFirstRow();
	                    cloneProductCodeRowId = cloneProductCodeRow.Id;
                        // set first Product Production in model to current Product Code
                        prodProductions.updateRow(prodProductionRow,{Product_Code__c: cloneProductCodeRowId});
                                // abandon first row from prodProductions as this row has been processed
                                // if any Product Productions still left then cycle again
                                    queryCloneModels(prodCount - + 1);
                                } else {
                                console.log('something went wrong updating and saving product production with new product code');

                        console.log('something went wrong saving models');
                console.log('something went wrong querying models');

        if ("clone") != -1){


    return dfd.promise();
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 43,156 Points 20k badge 2x thumb

Posted 4 years ago

  • 4
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,686 Points 5k badge 2x thumb
Nice recursion Pat! From Little League to the Majors in less than a year!
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,678 Points 20k badge 2x thumb
Fist pump indeed.  I agree with Moshe.  You are approaching Skuid Javascript Guru status.