I have created controller and visual force pages using handson table grid format. If I change the any record in the grid it update in related object. My controller and class working fine but not the update in related object please find the below images. enter image description here


global without sharing class OpportunityLineItemController{
public OpportunityLineItemController(ApexPages.StandardController controller){
public String OpportunityLineItem { get; set; }
public string volumeJSON {get;set;} 
// Constructor
public OpportunityLineItemController(){ 

public void OpportunityLineItemList(){  

for(OpportunityLineItem oli: [select id, ListPrice,Name,TotalPrice,UnitPrice from OpportunityLineItem order by name]) {                                          
Map<String,Object> Volume = (Map<String,Object>)JSON.deserializeUntyped(JSON.serialize(oli));
if (String.isBlank(volumeJSON) ) volumeJSON = '[' + JSON.serialize(Volume); 
else volumeJSON = volumeJSON + ',' + JSON.serialize(Volume);  
volumeJSON = volumeJSON + ']';


public static List<OpportunityLineItem> Save(String OLIJSON) {
List<String> valuefromJS=new List<String>();
OLIJSON= OLIJSON.remove('[');
OLIJSON = OLIJSON.remove(']');  
OLIJSON= OLIJSON.replace('},{','}SPLIT{');
valuefromJS = OLIJSON.split('SPLIT');

List<OpportunityLineItem> volSave = new List<OpportunityLineItem>();    
for(Integer i=0; i<valuefromJS.size(); i++){
OpportunityLineItem v=(OpportunityLineItem) JSON.deserialize(valuefromJS[i], OpportunityLineItem.class);
update volSave; 

    return null;
<apex:page Standardcontroller="Opportunity" extensions="OpportunityLineItemController" action="{!OpportunityLineItemList}">
  <apex:form > 
  <apex:pageblock >    
      <!-- Handsontable library code -->    
     <script src="{!URLFOR($Resource.excelgrid,'handsontable/js/jquery-1.11.1.min.js')}" language="JavaScript" type="text/javascript"></script>
     <script src="{!URLFOR($Resource.excelgrid,'handsontable/js/handsontable.full.js')}" language="JavaScript" type="text/javascript"></script>    
<link rel="stylesheet" href="{!URLFOR($Resource.excelgrid,'handsontable/css/handsontable.full.css')}" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="{!URLFOR($Resource.excelgrid,'handsontable/css/samples.css')}" type="text/css" charset="utf-8" />
        <script type="text/javascript">
var changedData;
$(document).ready(function () {        
    data = {!volumeJSON} ,
    container = document.getElementById('volumes'),
    hot = new Handsontable(container, {
    data: data,
    minSpareRows: 0,
    colHeaders: true,
    contextMenu: true,
    maxRows: data.numberOfRows,
    colHeaders: ['Model','Version','Discount','Volumes'],  
    columns: [           
        {data: 'Name', type: 'numeric'},
        {data: 'ListPrice', type: 'numeric'},
        {data: 'TotalPrice', type : 'numeric'},
        {data: 'UnitPrice ', type: 'numeric'},           
    contextMenu: ['undo', 'redo'] ,        
    afterChange: function (change, source) {                          
       if(source == 'edit'){      
          OpportunityLineItemController.Save(JSON.stringify(data), function(results, event){
            if(event.status) { alert('success'); }
            else             { alert(event.status);    }
<div class="handsontable" id="volumes"></div>

1 Answer 1


You need to rewrite your controller so that the update occurs either on the contents of Volume or else such that when you're passing the field values back to the controller through your JS, they're associated with an OLI Id. I don't see where you're doing that at the moment. That's why the update to the records isn't being committed. From the looks of your code, the new field values aren't connected with an OLI Id.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .