Skip to main content

I’m getting a VF remoting exception: “list index out of bounds: 1”

It’s happening when I attempt a save on the FollowupInteractions model after running the code at the end of this post.

Here’s the json string that VF exception is returning. I’m guessing that the “1” under “changes” is the problem?


{&nbsp; "operations": ;<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; "id": "FollowupInteractions",<br>&nbsp; &nbsp; &nbsp; "type": "Interaction__c",<br>&nbsp; &nbsp; &nbsp; "updates": a<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Date__c",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Interaction_Category__c",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Interaction_Purpose__c",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Interaction_Type__c",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Status__c",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Patient_Case__c",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Patient_Case__r.Name",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "id": "Follow_up_Attempts__c",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "targetObjects": null<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; ],<br>&nbsp; &nbsp; &nbsp; "changes": {<br>&nbsp; &nbsp; &nbsp; &nbsp; "1": {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Patient_Case__c": "a0wo0000002ul8fAAA",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Interaction_Category__c": "Follow-up",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Date__c": "2015-12-17T23:30:00.000Z",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Follow_up_Attempts__c": "4",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Status__c": "Scheduled",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Interaction_Purpose__c": "4 week follow-up",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Interaction_Type__c": "Call"<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; "2": {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Patient_Case__c": "a0wo0000002ul8fAAA",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Interaction_Category__c": "Follow-up",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Date__c": "2016-06-22",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Follow_up_Attempts__c": "1",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Status__c": "Scheduled",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Interaction_Purpose__c": "Chart closing",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Interaction_Type__c": "Other"<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; "a0ro0000000HypUAAS": {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Status__c": "Cancelled"<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; "a0ro0000000HypTAAS": {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Status__c": "Cancelled"<br>&nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; "a0ro0000000HypSAAS": {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Status__c": "Cancelled"<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>&nbsp; ]<br>}


Here’s the code:


var $ = skuid.$;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>//Get models and rows<br>var mI = skuid.$M('ThisInteraction'),<br>&nbsp; &nbsp; mC = skuid.$M('PatientCase'),<br>&nbsp; &nbsp; mF = skuid.$M('FollowupInteractions');<br>var rI = mI.getFirstRow(),<br>&nbsp; &nbsp; rC = mC.getFirstRow();<br><br>////////////////////////////////////////<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Helper Functions &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//<br>////////////////////////////////////////<br>var getClosingDate = function(){<br>&nbsp; &nbsp; var edd = rC.Estimated_Due_Date_by_U_S__c || rC.Estimated_Due_Date_LMP__c;<br>&nbsp; &nbsp; if (!edd) {<br>&nbsp; &nbsp; &nbsp; &nbsp; edd = skuid.time.parseSFDate(rC.LMP__c) || new Date();<br>&nbsp; &nbsp; &nbsp; &nbsp; edd.setDate(edd.getDate() + 40*7);<br>&nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; edd = skuid.time.parseSFDate(edd);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; var closingDate = new Date();<br>&nbsp; &nbsp; closingDate.setFullYear(edd.getFullYear(), edd.getMonth(), edd.getDate() + 4*7);<br>&nbsp; &nbsp; return skuid.time.getSFDate(closingDate);<br>};<br>var makeFollowup = function(model, date, attempt, purpose, type){<br>&nbsp; &nbsp; //Create row<br>&nbsp; &nbsp; model.createRow({<br>&nbsp; &nbsp; &nbsp; &nbsp; additionalConditions:;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Date__c', value: date},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Follow_up_Attempts__c', value: attempt},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Status__c', value: 'Scheduled'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Interaction_Category__c', value: 'Follow-up'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Interaction_Purpose__c', value: purpose},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Interaction_Type__c', value: type}<br>&nbsp; &nbsp; &nbsp; &nbsp; ]<br>&nbsp; &nbsp; });<br>};<br>var cancelScheduled = function(model){ &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; //Cancel all future interactions<br>&nbsp; &nbsp; var rowsToUpdate = {},<br>&nbsp; &nbsp; &nbsp; &nbsp; now = new Date();<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; //check followup interactions model for future scheduled follow-up interactions<br>&nbsp; &nbsp; $.each(model.getRows(), function(){<br>&nbsp; &nbsp; &nbsp; &nbsp; if (skuid.time.parseSFDateTime(this.Date__c) &gt; now &amp;&amp; this.Status__c == 'Scheduled') {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rowsToUpdate&this.Id] = { Status__c: 'Cancelled' };<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; });<br>&nbsp; &nbsp; model.updateRows( rowsToUpdate );&nbsp;<br>};<br>////////////////////////////////////////<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Action &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//<br>////////////////////////////////////////<br>if (rI.Interaction_Purpose__c === 'After due-date follow-up') {<br>&nbsp; &nbsp; var dt = skuid.time.parseSFDateTime(rI.Date__c);<br>&nbsp; &nbsp; dt.setDate(dt.getDate() + 1);<br>&nbsp; &nbsp; var newDate = skuid.time.getSFDateTime(dt);<br>&nbsp; &nbsp; makeFollowup(mF, newDate, '1', 'Chart closing', 'Other');<br>&nbsp; &nbsp;&nbsp;<br>} else {<br>&nbsp; &nbsp; //check follow-up status<br>&nbsp; &nbsp; switch (rI.Status__c) {<br>&nbsp; &nbsp; &nbsp; &nbsp; case 'Unsuccessful':<br>&nbsp; &nbsp; &nbsp; &nbsp; case 'Left message': &nbsp; &nbsp; &nbsp; &nbsp;//We did not make a connection.&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var attempt = rI.Follow_up_Attempts__c;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!attempt) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attempt = 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mI.updateRow(rI, {Follow_up_Attempts__c: '1'});<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var dt = skuid.time.parseSFDateTime(rI.Date__c);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.setDate(dt.getDate() + 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var newDate = skuid.time.getSFDateTime(dt);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //If we haven't tried three times<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (attempt &lt; 3) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//create new row for next attempt<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Get vairables for new row<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attempt++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; makeFollowup(mF, newDate, attempt.toString(), rI.Interaction_Purpose__c, rI.Interaction_Type__c);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelScheduled(mF);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!rC.Pregnancy_Confirmed__c){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Create final followup attempt with certified letter<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; makeFollowup(mF, newDate, '4', rI.Interaction_Purpose__c, 'Certified Letter');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Create 'Awesome Christina' follow-up attempt 4 for patients who still intend to abort<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (rC.Pregnancy_Intention__c == 'Abort') {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mF.createRow({<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; additionalConditions:;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Date__c', value: newDate},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Follow_up_Attempts__c', value: '4'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Status__c', value: 'Scheduled'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Interaction_Category__c', value: 'Follow-up'},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Interaction_Purpose__c', value: rI.Interaction_Purpose__c},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Interaction_Type__c', value: rI.Interaction_Type__c},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {field: 'Primary_Staff__c', value: '005o0000002PSJR'} //Christina<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var closingDate = getClosingDate();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; makeFollowup(mF, closingDate, '1', 'Chart closing', 'Other');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; &nbsp; case 'Hung-up': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //If patient hung up, do not call again.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mC.updateRow(rC, {Patient_Requests_No_Further_Contact__c: true});<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelScheduled(mF);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var closingDate = getClosingDate();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; makeFollowup(mF, closingDate, '1', 'Chart closing', 'Other');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; &nbsp; case 'Successful': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//We made a connection<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (rC.Patient_Requests_No_Further_Contact__c) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelScheduled(mF);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var closingDate = getClosingDate();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; makeFollowup(mF, closingDate, '1', 'Chart closing', 'Other');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (rC.Pregnancy_Outcome__c &amp;&amp; rC.Pregnancy_Outcome__c !== 'Still Pregnant') { // There was a closing event<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelScheduled(mF);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var dt = new Date();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.setDate(dt.getDate() + 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var newDate = skuid.time.getSFDateTime(dt);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; makeFollowup(mF, newDate, '1', 'Chart closing', 'Other');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; }<br>}<br><br>$.blockUI({<br>&nbsp; &nbsp; message: 'Processing Complete.',<br>&nbsp; &nbsp; timeout: 2000<br>});

Looks like you’re trying to send a date into a datetime field. Notice the value you’re sending for “changes” -> “2” -> “Date__c”


That was it! Thanks.


Reply