Dear Experts /Claudia Pacheco/Jitendra Kansal/ Midhun VP - SCN Member of the Month May 2014Jitendra Kansal,
I am facing a problem when I am trying to push multiple rows for Update operation into a single request. I am using Batch request, for multiple data its not working for me, below are the code I am using for Update Operation . Please suggest for the same.
NOTE : When I update single row same code is working for me but for multiple files same code not woking giving error with ERROR Code 500.
public static String updateReassignLeadBatch(ArrayList<ReassignBean> leadData, String userCode) throws OfflineODataStoreException {
String code = "";
if (createOfflineStore == null)
return "";
try {
//Creates the entity payload
// //Note: headers may not be required... test with and without it in case of issues
Map<String, String> createHeaders = new HashMap<String, String>();
createHeaders.put("accept", "application/atom+xml");
createHeaders.put("content-type", "application/atom+xml");
ODataRequestParamBatch RequestParamBatch = new ODataRequestParamBatchDefaultImpl();
ODataRequestChangeSet updateLead = new ODataRequestChangeSetDefaultImpl();
ODataEntity newEntity = new ODataEntityDefaultImpl("AppModel.user_RetailData");
newEntity.getProperties().put("USER_Code", new ODataPropertyDefaultImpl("\"USER_Code\"", userCode));
ODataRequestParamSingle batchItem = null;
for (int i = 0; i < leadData.size(); i++) {
//Creating Batch Item
batchItem = new ODataRequestParamSingleDefaultImpl();
batchItem.setResourcePath("user_RetailData(" + leadData.get(i).regCode + "L)");
batchItem.setMode(ODataRequestParamSingle.Mode.Update);
batchItem.setCustomTag("Batch Request to Update");
batchItem.setPayload(newEntity);
batchItem.setOptions(createHeaders);
//Creting Batch Set
updateLead.add(batchItem);
RequestParamBatch.add(updateLead);
}
ODataResponse dataResponse = createOfflineStore.executeRequest(RequestParamBatch);
Map<ODataResponse.Headers, String> headerMap = dataResponse.getHeaders();
if (headerMap != null) {
code = headerMap.get(ODataResponse.Headers.Code);
}
} catch (Exception e) {
// System.out.println("Record create func in exception");
throw new OfflineODataStoreException(e);
}
return code;
}