Serves to load external data into Salesforce.com or Database.com.
The following example creates a
SalesforceLoader, then populates Columns collection from table description, loads data, flushes the buffer, and disposes internal
SalesforceLoader structures. The
SalesforceLoader requires an open connection.
public void LoadData(SalesforceConnection myConnection) {
myConnection.Open();
SalesforceLoader loader = new SalesforceLoader();
loader.Connection = myConnection;
loader.TableName = "Account";
try {
loader.CreateColumns();
loader.Open();
for (int i = 1; i <= 10; i++) {
loader.SetValue("Name", "Test account" + i.ToString());
loader.SetValue("Type", "Customer - Direct");
loader.NextRow();
}
loader.Close();
}
catch (SalesforceLoaderException ex) {
int recordsSucceded = ex.RecordsSucceded;
int recordsFailed = ex.RecordsFailed;
if (recordsFailed > 0) {
SalesforceLoaderResult[] results = loader.GetResults();
foreach (var result in results) {
if (!result.Success) {
// process error...
Console.WriteLine(result.ErrorText);
}
}
}
else if (ex.Errors.Count > 0) {
foreach (SalesforceError err in ex.Errors)
// process error...
Console.WriteLine(err.Message);
}
else
Console.WriteLine(ex.Message);
}
finally {
myConnection.Close();
}
}
Public Sub LoadData(myConnection As SalesforceConnection)
myConnection.Open()
Dim loader As New SalesforceLoader()
loader.Connection = myConnection
loader.TableName = "Account"
Try
loader.CreateColumns()
loader.Open()
For i As Integer = 1 To 10
loader.SetValue("Name", "Test account" & i.ToString())
loader.SetValue("Type", "Customer - Direct")
loader.NextRow()
Next
loader.Close()
Catch ex As SalesforceLoaderException
Dim recordsSucceded As Integer = ex.RecordsSucceded
Dim recordsFailed As Integer = ex.RecordsFailed
If recordsFailed > 0 Then
Dim results As SalesforceLoaderResult() = loader.GetResults()
For Each result As var In results
If Not result.Success Then
' process error...
Console.WriteLine(result.ErrorText)
End If
Next
ElseIf ex.Errors.Count > 0 Then
For Each err As SalesforceError In ex.Errors
' process error...
Console.WriteLine(err.Message)
Next
Else
Console.WriteLine(ex.Message)
End If
Finally
myConnection.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2