dotConnect for Salesforce Documentation
In This Topic
    GetCustomReport Procedure for Running Salesforce Reports
    In This Topic

    dotConnect for Salesforce allows getting the results of Salesforce reports by performing a call to the GetCustomReport procedure via SalesforceCommand. This stored procedure returns data, returned by your Salesforce report with the specified ID.

    Here is an example how you may call this stored procedure:

    using (SalesforceConnection connection = new SalesforceConnection(
      "Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;"
    )) {
      connection.Open();
      using (SalesforceCommand command = connection.CreateCommand()) {
    
        command.CommandText = "call GetCustomReport('00OA000000614QN')";
        SalesforceDataReader reader = command.ExecuteReader();
        
        ...
        
        }
      }
    
    
    
    
        Using connection As SalesforceConnection = New SalesforceConnection("Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;")
            connection.Open()
    
            Using command As SalesforceCommand = connection.CreateCommand()
                command.CommandText = "call GetCustomReport('00OA000000614QN')"
                Dim reader As SalesforceDataReader = command.ExecuteReader()
                
                ...
                
            End Using
        End Using
    
    
    

    You may also use an optional second ReportFilter parameter to filter and sort report data.

    using (SalesforceConnection connection = new SalesforceConnection(
      "Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;"
    )) {
      connection.Open();
      using (SalesforceCommand command = connection.CreateCommand()) {
    
        command.CommandText = "call GetCustomReport('00OA000000614QN','WHERE FirstName = ''Tom'' OR FirstName = ''Jim'' ORDER BY LastName')";
        SalesforceDataReader reader = command.ExecuteReader();
        
        ...
        
        }
      }
    
    
    
    
        Using connection As SalesforceConnection = New SalesforceConnection("Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;")
            connection.Open()
    
            Using command As SalesforceCommand = connection.CreateCommand()
                command.CommandText = "call GetCustomReport('00OA000000614QN','WHERE FirstName = ''Tom'' OR FirstName = ''Jim'' ORDER BY LastName')"
                Dim reader As SalesforceDataReader = command.ExecuteReader()
                
                ...
                
            End Using
        End Using
    
    
    

    The ReportFilter parameter must contain a WHERE clause that includes one or more simple conditions, united with AND or OR logical operators. NOT operator and brackets are also acceptable.

    The conditions must be simple: "column operator value". Expressions are not supported. The following operators can be used: =, !=, <,<=,>,>=. You can also check for conditions if a column "is null" or "is not null".

    The WHERE clause may be followed by an optional ORDER BY clause. Note that the ORDER BY clause can include only one field.

    You can also run this stored procedure, assigning System.Data.CommandType.StoredProcedure to the CommandType property of SalesforceCommand:

    using (SalesforceConnection connection = new SalesforceConnection(
      "Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;"
    )) {
      connection.Open();
      using (SalesforceCommand command = connection.CreateCommand()) {
    
        command.CommandText = "GetCustomReport";
        command.CommandType = System.Data.CommandType.StoredProcedure;
        command.Parameters.Add("ReportId", SalesforceType.String).Value = "00OA000000614QN";
        command.Parameters.Add("ReportFilter", SalesforceType.String).Value = "WHERE FirstName = 'Tom'";
        SalesforceDataReader reader = command.ExecuteReader();
        
        ...
        
        }
      }
    
    
    
    
    
    Using connection As SalesforceConnection = New SalesforceConnection("Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;")
        connection.Open()
    
        Using command As SalesforceCommand = connection.CreateCommand()
            command.CommandText = "GetCustomReport"
            command.CommandType = System.Data.CommandType.StoredProcedure
            command.Parameters.Add("ReportId", SalesforceType.String).Value = "00OA000000614QN"
            command.Parameters.Add("ReportFilter", SalesforceType.String).Value = "WHERE FirstName = 'Tom'"
            Dim reader As SalesforceDataReader = command.ExecuteReader()
        End Using
    End Using
    
    
    

    Parameter names are not mandatory. You can use any names, but the first parameter must contain the ID of the report, and the second, optional parameter should contain the WHERE and/or ORDER BY clause.