Save table then update records to reflect Salesforce Id from first row

  • 1
  • Question
  • Updated 5 years ago
  • Answered
Archived and Closed

This conversation is no longer open for comments or replies and is no longer visible to community members. The community moderator provided the following reason for archiving: Fixed Bugs, Redundant Posts

Use case: Save a model then update 'RecurrenceApptId' on all the saved rows with the Id of the first row

1. Save model from a table

var params = arguments[0],    $ = skuid.$;//get models New Quote Model to save
//your model variable wasn't called "m"...
var m = skuid.model.getModel('newAppts');
r = m.getFirstRow();
skuid.model.save({callback:function(result){
if(result.totalsuccess){
alert('Recurrence Appt Id: ' + r.Id); // should be a real SF Id now
}else{
// I have no idea what insert results are but if it works for you...
// There was a problem. Let's see what went wrong.
      alert('Error: ' + result.insertResults[0]);
      console.log(result.insertResults[0]);
}
}});

2. Update all the rows - not sure how to do this



I'm pretty sure this is an easy one, but I can't quite finish it off.
Photo of Griffin Brown

Griffin Brown

  • 2,818 Points 2k badge 2x thumb
  • happy

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,784 Points 50k badge 2x thumb
var params = arguments[0],    
    $ = skuid.$;
//get models New Quote Model to save
//your model variable wasn't called "m"...
var m = skuid.model.getModel('newAppts');
r = m.getFirstRow();
// Specify the models to save --- this was missing
skuid.model.save([m],{callback:function(result){
if(result.totalsuccess){
    var firstRowId = m.getFirstRow().Id;
    alert('Recurrence Appt Id: ' + firstRowId); // should be a real SF Id now
    var rowUpdates = {};
    $.each(m.getRows(),function(i,row){
         rowUpdates[row.Id] = {
             'RecurrenceApptId__c': firstRowId
         };
    });
    m.updateRows(rowUpdates);
}else{
// I have no idea what insert results are but if it works for you...
// There was a problem. Let's see what went wrong.
      alert('Error: ' + result.insertResults[0]);
      console.log(result.insertResults[0]);
}
}});
Photo of Griffin Brown

Griffin Brown

  • 2,818 Points 2k badge 2x thumb
#awesome
Photo of Griffin Brown

Griffin Brown

  • 2,818 Points 2k badge 2x thumb
So, when I used the code above, it is create the the rows perfectly but it isn't updating the RecurrenceApptId__c  with firstRowId. The firstRowId var is accurate (via console.log). The rowUpdates var is accurate (via console.log) and returns an array of record ids. 

Any tips on what I could be doing wrong?
Photo of Griffin Brown

Griffin Brown

  • 2,818 Points 2k badge 2x thumb
Derkah derr - I forgot to save the model after the update

This conversation is no longer open for comments or replies.