executeInsert(DARequest)
This function inserts new records to the local offline database including attachments.
Function Signature: executeInsert(DARequest)
Function Name: executeInsert
Parameter: DARequest
Sample Code:
DARequest objDAReq = new DARequest();
objDAReq.UserName = "tech@acme.com";
objDAReq.APIKey = "LVaNcHj01asdLX10bBxst2hC6AbsEaWSQSxpknfCjaJ8GKYIa9ZD66++8VYXXxqL";
objDAReq.ObjectName = "Account";

ArrayList arrFD = new ArrayList();

FieldData objFD = new FieldData();
objFD.setName = ("Name");
objFD.setValue = ("Burlingame");
objFD.setType = ("string");
arrFD.Add(objFD);

objFD = new FieldData();
objFD.setName = ("Type");
objFD.setValue = ("Other");
objFD.setType = ("picklist");
arrFD.Add(objFD);

objFD = new FieldData();
objFD.setName = ("BillingStreet");
objFD.setValue = ("Main Street");
objFD.setType = ("textarea");
arrFD.Add(objFD);

objDAReq.FieldNames = arrFD;

LaptopMobile.DataAccessAPI.DataAccessAPI objDAAPI = new LaptopMobile.DataAccessAPI.DataAccessAPI();

objDAAPI.executeInsert(objDAReq);
if (objDAReq.DAResponse.responseCode == 1)
{
System.Diagnostics.Debug.WriteLine("Response: " + objDAReq.Response);
}
else
{
System.Diagnostics.Debug.WriteLine("Failure Response: " + objDAReq.Response);
}
Sample Success response:
{
"Object Name":"Account",
"Response Code":1,
"Response Message":"MSG-005: Record(s) inserted successfully. Number of rows inserted: 1",
"Output": [
{
"id":"001_local_30151109450"

}

],
"Error Id":"",
"Error Message":"",
"Error Description":"",
"Stack Trace":""
}
Sample Failure response:
{
"Object Name":"Account",
"Response Code":0,
"Response Message":"ERR-010: Error inserting records. Data type mismatch.",
"Error Id":"ERR-010",
"Error Message":"ERR-010: Error inserting records. Data type mismatch.",
"Error Description":"",
"Stack Trace":""
}
Sample code in case of Attachment Record insertion:
DARequest objDAReq = new DARequest();
objDAReq.UserName = "tech@acme.com";
objDAReq.APIKey = "LVaNcHj01asdLX10bBxst2hC6AbsEaWSQSxpknfCjaJ8GKYIa9ZD66++8VYXXxqL";
objDAReq.ObjectName = "Attachment";
objDAReq.ReferenceObjectName= "SVMXC__Service__Order__c";
objDAReq.SourceLocation = "c:/test.doc";

ArrayList arrFD = new ArrayList();

FieldData objFD = new FieldData();
objFD.setName = ("Name");
objFD.setValue = ("test.doc");
objFD.setType = ("string");
arrFD.Add(objFD);

objFD = new FieldData();
objFD.setName = ("parent_id");
objFD.setValue = ("a1y0R000000Z3zQQAS");
objFD.setType = ("reference");
arrFD.Add(objFD);

objDAReq.FieldNames = arrFD;

LaptopMobile.DataAccessAPI.DataAccessAPI objDAAPI = new LaptopMobile.DataAccessAPI.DataAccessAPI();

objDAAPI.executeInsert(objDAReq);
if (objDAReq.DAResponse.responseCode == 1)
{
System.Diagnostics.Debug.WriteLine("Response: " + objDAReq.Response);
}
else
{
System.Diagnostics.Debug.WriteLine("Failure Response: " + objDAReq.Response);
}
Sample Success response:
{
"Object Name":"Attachment",
"Response Code":1,
"Response Message":"MSG-005: Record(s) inserted successfully. Number of rows inserted: 1",
"Output": [
{"id":"001_local_30151109550"
}
],
"Error Id":"",
"Error Message":"",
"Error Description":"",
"Stack Trace":""
}
Sample Failure response:
{
"Object Name":"Attachment",
"Response Code":0,
"Response Message":"ERR-010: Error inserting records. Data type mismatch.",
"Error Id":"ERR-010",
"Error Message":"ERR-010: Error inserting records. Data type mismatch.",
"Error Description":"",
"Stack Trace":""
}
Points to remember when performing attachment insert:
1. name and parent_id parameters are mandatory. Description is an optional field. Usage of any other parameters other than these three may result in failure of the API call.
2. The name should contain the name of the file, with its extension. The name of the file should match the name of the file in the source location.
3. The parent_id should be a valid 18-digit sfdc id. The record should be available in the client side.
4. The file should be available in the source location.
5. The object name should be mentioned as attachment.
6. The reference object name is mandatory and should be the API name of a valid salesforce object.
7. Files of size up to 25MB are allowed as attachment.
8. The attachment API works only with the default values for the UploadDirectory and DownloadDirectory present in the config file. No other locations are supported.
Was this helpful?