I created a upload Visual Force page which selects a CSV file and read in the contents. With the file data I call a Apex remote action. The remote action method does a upsert into a custom object. If the file is larger then 1400 records I receive an error that the memory size to greater then 1 Meg. To fix this I broke up the data which was read in from the file into 1000 record chunks. After each 1000 records is read I call the remote action. This causes another problem Upsert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] The first fix I tried was to delay between remote calls. This is not a 100% fix. I am still getting errors on IE 11. What can I do to handle larger amounts of record?
Thank you, Dan Glaser
I would like to give a better explanation of the problem. I am using Javascript to select and read a CSV files data.
var files = evt.target.files; // FileList object which is called by an eventhandler.
I process the data by reading in each record and putting the data into an javascript array. the data comes from var data = $.csv.toArrays(csv); where CSV is the data from the file var csv = event.target.result . Once a 1000 records are put into the array the array is passed to the remoteaction call via:
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.ProductMasterUploadController.upsertProdMaster}',
masterItems,
function(result, event) {
isExecuting=false;
if ( event.status ) {
numbercomplete++;
if ( numbercomplete >= partialuploads ) {
document.getElementById("WaitStatus").innerHTML = " Completed! ";
$("#loading").hide();
$("#uploadmsg").hide();
} else {
document.getElementById("WaitStatus").innerHTML = " Processed "+numbercomplete+" of "+partialuploads;
}
} else if ( event.type === 'exception' ) {
document.getElementById("responseErrors").innerHTML = event.message + "<br/>\n<pre>" + event.where + "</pre><br>";
remoteresults = 0;
uploadError = true;
} else {
document.getElementById("responseErrors").innerHTML = event.message;
remoteresults = 0;
uploadError = true;
}
},
{ buffer: false, escape: true, timeout: 60000}
);
The apex code is very basic:
@RemoteAction
public static void upsertProdMaster(List<Customer_Product_Master__c> masterItems){
Customer_Product_Master__c [] prodmstr = [SELECT Id FROM Customer_Product_Master__c LIMIT 2 FOR UPDATE];
upsert masterItems External_ID__c;
}