dotConnect for Salesforce Documentation
Devart.Data.Salesforce Namespace / SalesforceLoader Class
Members Example

In This Topic
    SalesforceLoader Class
    In This Topic
    Serves to load external data into Salesforce.com or Database.com.
    Syntax
    'Declaration
     
    Public NotInheritable Class SalesforceLoader 
       Inherits Devart.Common.DbLoader
       Implements System.ComponentModel.IComponentSystem.IDisposable 
    public sealed class SalesforceLoader : Devart.Common.DbLoader, System.ComponentModel.IComponentSystem.IDisposable  
    Remarks

    SalesforceLoader unites records to insert into batches and sends them to the server. Note that the data are actually processed at the server and inserted to a table only when you call Close. Do not forget to call this method after you sent all the data.

    See Bulk Data Loading for more information on using the SalesforceLoader component.

    Example
    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
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             Devart.Common.DbLoader
                Devart.Data.Salesforce.SalesforceLoader

    Requirements

    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

    See Also