How to Connect to Salesforce in Delphi Using UniDAC
Delphi applications often require reliable connectivity to external data sources, and UniDAC is the ideal solution for this. It provides a simple and efficient way to connect Delphi to popular platforms like Salesforce for flawless data integration and management. With UniDAC, you can rely on establishing a dependable connection to Salesforce and easily retrieve and manipulate Salesforce data.
Why UniDAC?
UniDAC (Universal Data Access Components) is a powerful set of data access components designed for Delphi and C++ Builder. It provides a uniform interface for connecting to a wide range of databases, allowing developers to work with different data sources without needing to write separate code for each one.
UniDAC supports a variety of database systems, including MySQL, PostgreSQL, SQLite, Oracle, SQL Server, and others. The main advantage of UniDAC is its ability to provide seamless connectivity to multiple database types using a single set of components, making it an ideal choice for projects that require interaction with different data sources.
UniDAC also supports modern authentication methods such as OAuth 2.0, which is especially useful when connecting to cloud services like Salesforce. This makes UniDAC suitable for both secure enterprise environments and personal development projects.
Why connect Delphi with Salesforce CRM?
By integrating Delphi applications with Salesforce, you enhance the functionality of both solutions and create services that leverage the capabilities of both Delphi and Salesforce, delivering strong business value:
- Centralized data management
Integrations between Delphi and Salesforce bridge the gap between local systems and cloud-based CRM workflows, enabling bi-directional data synchronization and exchange. Such data management systems ensure data consistency, integrity, and trust, improving performance and facilitating governance and compliance.
- Better customer insights
Data synchronization between Delphi applications and Salesforce empowers sales representatives and analysts with full knowledge of customer interactions, improving personalization and targeting and increasing service quality.
- Enhancement of custom sales tools
Through integration, the business logic of custom Delphi applications can be made available to Salesforce users, while the agility of Salesforce workflows improves the performance of Delphi solutions.
- Higher operational efficiency
Database synchronization between Delphi and Salesforce maintains data consistency and facilitates handling by minimizing manual work and enabling automation.
Common challenges in Delphi-Salesforce integration
Different organizational principles of Delphi and Salesforce may present certain challenges that sometimes arise during integration. Below is a list of complexities that are frequently encountered when integrating Delphi applications and Salesforce.
| Challenge | Solution |
|---|---|
| Implementing OAuth 2.0 authentication Salesforce requires token-based OAuth 2.0 authentication with tokens to be refreshed frequently. Delphi needs additional token handlers to securely store and refresh tokens. |
Implement a token handler manually in Delphi using additional Delphi libraries. As an alternative, opt for basic authentication with a username, password, and security token. |
| Salesforce API complexity Salesforce API formats and objects cannot be directly mapped to Delphi structures. |
Use UniDAC or ODBC drivers or other third-party libraries or components to connect Delphi apps to Salesforce. |
| Nested JSON handling Salesforce API responses often contain deeply nested JSON, which can be difficult to parse in Delphi. |
Implement Delphi libraries, custom functions, or third-party tools to parse JSON into Delphi structures. |
| Lack of native Salesforce tools in Delphi Delphi has no built-in tools intended for Salesforce integration. |
Take advantage of ODBC drivers for Salesforce to enable database connectivity with Delphi applications; for data management, use middleware solutions. |
Key benefits of using Devart UniDAC for Salesforce integration
Devart UniDAC is a library of components that enable direct access to multiple cloud services and database management systems, Salesforce being one of them. Choosing UniDAC as your Delphi-Salesforce connector allows you to resolve major integration challenges and provides high-performance interface to Salesforce CRM. In addition to intuitive setup and configuration, UniDAC brings other tangible benefits:
- Native integration with OAuth and REST API
- Unified SQL interface for Salesforce objects
- Support for development of applications using data hosted in cloud services
- Component-based development that supports modular application design
- Advanced data synchronization enabling data management across multiple sources
- Secure connection between the database server and client
Connect to Salesforce from Delphi using UniDAC
- RAD Studio installed on your system.
- UniDAC from Devart installed.
- Salesforce connection details: username, password, and security token.
- Devart ODBC Driver for Salesforce installed. The driver is sold and distributed separately from UniDAC.
Step 1. Install ODBC Driver for Salesforce
- Download the Driver.
- Launch the downloaded installer and follow the step-by-step instructions in the setup wizard.
Step 2. Configure connection to Salesforce via UniDAC
- Launch your RAD Studio.
- Navigate to File > New > Windows VCL Application - Delphi to create a new Delphi project.
-
Add the TUniConnection component to your form.
- 3.1 Navigate to the Component palette and locate the UniDAC category.
- 3.2 Drag the TUniConnection component and drop it onto the Form Designer.
-
Double-click the UniConnection1 label on the form to open the configuration dialog, and provide the following TUniConnection properties:
- In the Provider dropdown menu, select Salesforce.
- In the Server field, enter your Salesforce URL.
- In the Username field, enter your Salesforce username.
- In the Password field, enter your Salesforce password.
- Go to the Options tab and in the Security Token field enter your Salesforce security token.
- Return to the Connect tab and click Connect.
Configure connection from the Code Editor
To set up a connection to Salesforce using the Code Editor, use the TUniConnection component from UniDAC. Start by placing the component on your form. Then, open the Code Editor and configure the TUniConnection properties programmatically to establish the connection.
// Create and configure TUniConnection
UniConnection1 := TUniConnection.Create(nil);
try
UniConnection1.ProviderName := 'Salesforce';
UniConnection1.Server := 'login.salesforce.com';
UniConnection1.Username := 'your_username';
UniConnection1.Password := 'your_password';
UniConnection1.SpecificOptions.Values['SecurityToken'] := 'your_security_token';
// Attempt to connect
UniConnection1.Connect;
if UniConnection1.Connected then
ShowMessage('Connection to Salesforce was successful!')
else
ShowMessage('Failed to connect to Salesforce.');
except
on E: Exception do
ShowMessage('Error: ' + E.Message);
end;
You can place this code within a method that you call when your form is created or when a specific event is triggered.
Retrieve and manage Salesforce data via UniDAC at design time
UniDAC enables you to connect to Salesforce and access its data visually right from the design-time environment. You can browse tables, run queries, and modify data—all without writing a single line of code.
Access Salesforce data visually in RAD Studio
To retrieve data from Salesforce:
- Navigate to the Component palette, locate the UniDAC category, and drag the TUniQuery and TUniDataSource components onto your form.
- Similarly add the TSalesforceUniProvider component: drag and drop it from the UniDAC Cloud Providers category.
- Finally, add the TButton component from the Standard category and TDBGrid from the Data Controls category.
- Click the DBGrid1 label in the Form Designer and set the DataSource property to the UniDataSource1 value in the Object Inspector.
- Click the UniDataSource1 label in the Form Designer and set the DataSet property to the UniQuery1 value in the Object Inspector.
- Double-click the UniQuery1 label in the Form Designer and enter a query to select the data from Salesforce. For example:
SELECT * FROM CaseStatus;
- Click OK to save changes and close the dialog.
- Run the application by clicking Run, then click Button1 to activate the query and display the results.
Manipulate Salesforce data visually in RAD Studio
You can also add, edit, or delete Salesforce data at design time. What's more, you don't need to write a single line of code for that.
- Add a new TUniQuery component to the Form Designer, or adjust the existing one as needed.
- In the Form Designer, select the UniQuery1 component and set its Active property to True in the Object Inspector.
- Double-click the UniQuery1 component in the Form Designer and enter a SQL query to insert, delete, or update data in the Salesforce database. For example:
UPDATE Account
SET Name = 'Acme Corporation',
Industry = 'Technology',
Phone = '123-456-7890'
WHERE Id = '0015g00000NQvXcAAL';
- Click Execute, then click OK to close the dialog.
- Check the result.
In a similar way, you can delete or update data in Salesforce.
Manage Salesforce data using UniDAC at runtime
Select Salesforce data using code
To retrieve data from Salesforce at runtime with UniDAC—a robust library for universal data access—you can use the TUniQuery component. It allows you to write and run SQL queries using familiar, standard syntax.
- Add the TUniQuery, TUniDataSource, and TSalesforceUniProvider components to your form.
- In the Form Designer, select the UniDataSource1 component and set its DataSet property to UniQuery1 in the Object Inspector.
- Double-click the UniQuery1 label in the Form Designer and enter a query to select the data from Salesforce.
- Click OK to save changes and close the dialog.
- Execute the query at runtime.
Example code in Delphi:
procedure TForm10.Button1Click(Sender: TObject); begin UniQuery1.Open end;
Insert, update, or delete Salesforce data at runtime
Insert data
To insert data into a Salesforce table at runtime, use the INSERT INTO SQL statement. Parameters can be used to pass values dynamically.
Example code in Delphi:
procedure TForm1.InsertIntoAccountTable;
begin
// Link the TUniQuery component to the Salesforce connection
UniQuery1.Connection := UniConnection1;
// Write the SQL INSERT statement for the Account object
UniQuery1.SQL.Text := 'INSERT INTO Account (Name, Industry, Phone, Website) ' +
'VALUES (:Name, :Industry, :Phone, :Website)';
// Assign parameter values
UniQuery1.ParamByName('Name').AsString := 'Acme Corporation';
UniQuery1.ParamByName('Industry').AsString := 'Technology';
UniQuery1.ParamByName('Phone').AsString := '123-456-7890';
UniQuery1.ParamByName('Website').AsString := 'https://www.acme.com';
try
// Execute the query
UniQuery1.Execute;
ShowMessage('Account inserted successfully!');
except
on E: Exception do
ShowMessage('Failed to insert account: ' + E.Message);
end;
end;
Update data
To change existing records, use the UPDATE statement along with a WHERE clause to specify which rows to update.
Example code in Delphi:
procedure TForm1.UpdateAccountDetails;
begin
// Link the TUniQuery component to the Salesforce connection
UniQuery1.Connection := UniConnection1;
// Write the SQL update query for the Account object
UniQuery1.SQL.Text := 'UPDATE Account ' +
'SET Name = :Name, ' +
'Industry = :Industry, ' +
'BillingCity = :BillingCity, ' +
'Phone = :Phone, ' +
'Website = :Website ' +
'WHERE Id = :AccountID';
// Assign parameter values
UniQuery1.ParamByName('Name').AsString := 'Globex International';
UniQuery1.ParamByName('Industry').AsString := 'Manufacturing';
UniQuery1.ParamByName('BillingCity').AsString := 'Chicago';
UniQuery1.ParamByName('Phone').AsString := '312-555-9021';
UniQuery1.ParamByName('Website').AsString := 'https://www.globex.com';
UniQuery1.ParamByName('AccountID').AsString := '0013x00002ZB9aMAAT'; // Replace with valid Account Id
try
// Execute the query
UniQuery1.Execute;
ShowMessage('Account details updated successfully!');
except
on E: Exception do
ShowMessage('Failed to update account details: ' + E.Message);
end;
end;
Delete data
To remove records, use the DELETE FROM SQL statement along with a WHERE clause to identify the rows you want to delete.
Example code in Delphi:
procedure TForm1.DeleteAccountRecord;
begin
// Link the TUniQuery component to the Salesforce connection
UniQuery1.Connection := UniConnection1;
// Write the SQL DELETE statement
UniQuery1.SQL.Text := 'DELETE FROM Account WHERE Id = :AccountID';
// Set the Account ID to delete
UniQuery1.ParamByName('AccountID').AsString := '0018b00002abcXYAAY'; // Replace with the actual Account Id
try
// Execute the DELETE command
UniQuery1.Execute;
ShowMessage('Account record deleted successfully!');
except
on E: Exception do
ShowMessage('Failed to delete account: ' + E.Message);
end;
end;
Salesforce-specific options
UniDAC offers a unified interface for working with multiple cloud services, including Salesforce, while supporting detailed configuration tailored to each service. For Salesforce, these settings—called Salesforce-specific options—let you fine-tune connectivity and behavior. You can apply them through the SpecificOptions property, a string list available in components such as TUniConnection, TUniQuery, TUniTable, TUniStoredProc, and TUniSQL.
How to use Salesforce-specific options
The example below shows how Salesforce-specific options can be used in UniDAC components.
UniConnection1.SpecificOptions.Values['Authentication'] := 'atOAuth'; UniQuery1.SpecificOptions.Values['FieldsAsString'] := 'True';
Benefits of Salesforce-specific options in UniDAC
Salesforce-specific options in UniDAC provide key benefits by streamlining configuration, enhancing performance, and offering greater flexibility. With support for customizable authentication methods (OAuth 2.0 or basic), metadata caching, and proxy configuration, UniDAC enables smooth integration with Salesforce—even in complex enterprise environments.
Support for OAuth 2.0 authentication is one of the key advantages of UniDAC. By setting Authentication=atOAuth, you can securely connect to Salesforce without exposing sensitive login credentials in your code. This method is highly recommended for production environments and aligns with Salesforce's best practices for secure integrations.
Options like FieldsAsString and UseUnicode optimize data processing, ensuring reliable performance across diverse datasets and multilingual applications.
For long-running tasks, performance-oriented settings such as CommandTimeout and ConnectionTimeout increase stability, while UTCDates ensures consistent handling of datetime values across time zones. Together, these options empower developers to create secure, efficient, and scalable Salesforce-connected solutions that meet modern business needs.
Best practices checklist
- Use parameterized queries
Always use parameters in
TUniQueryto avoid SQL injection, ensure type safety, and improve maintainability. - Choose the appropriate authentication method
Use OAuth 2.0 for production environments to enhance security. Basic authentication (username, password, security token) is better suited for testing or internal tools.
- Set up
SpecificOptionsproperlyMake use of the UniDAC's
SpecificOptionsproperty to fine-tune behavior: - Handle connection errors gracefully
Wrap connection and query execution logic in
try...exceptblocks to handle authentication failures, timeouts, or API rate limits. - Use
CommandTimeoutandConnectionTimeoutSet these values explicitly to avoid application hangs during long-running operations or temporary API latency.
- Use separate
TUniConnectioninstances for background threadsEnsure thread safety by not sharing
TUniConnectionacross threads. Create a separate connection per thread if your application runs background tasks. - Avoid unnecessary full-table queries
Add WHERE clauses and LIMIT filters to minimize API usage and comply with Salesforce governor limits.
- Validate field and object names against Salesforce metadata
Double-check spelling and casing of field names, especially with custom fields, using Salesforce Object Reference or the Developer Console.
Conclusion
Connecting to Salesforce from Delphi using UniDAC is a simple and efficient process. Whether you're retrieving, inserting, or updating data, UniDAC handles the integration with ease—so you can focus on building powerful, data-driven applications. Try UniDAC for Salesforce today with a free trial and discover how it can accelerate development and elevate your Delphi projects. Build smarter, faster, and more scalable solutions with UniDAC.
FAQ
Yes. To connect to Salesforce through UniDAC, you will need a driver. We suggest you install Devart ODBC Driver for Salesforce, which acts as the bridge between your Delphi application and the Salesforce API.
UniDAC supports multiple authentication methods for connecting to Salesforce. The most secure and recommended option is OAuth 2.0, which is used by default. However, basic authentication—using a username, password, and security token—is also available. You can choose the authentication method by setting the appropriate value in the SpecificOptions property of the TUniConnection component.
Yes. UniDAC allows full access to both standard and custom objects. Just make sure to use the correct API names—custom objects and fields in Salesforce typically end with __c.
Yes. UniDAC supports full CRUD operations—you can insert, update, and delete Salesforce records using standard SQL syntax. Just ensure your Salesforce user account has the necessary permissions.
Absolutely. UniDAC enables you to connect and work with Salesforce visually at design time. You can use TUniQuery, TUniTable, and data-aware components like TDBGrid to view and manipulate data without writing code.
Use SpecificOptions such as FetchAll=True, CommandTimeout, and ConnectionTimeout to improve performance and stability when working with large volumes of data or long-running operations.
Yes, but each thread must use its own instance of TUniConnection and related components. Avoid sharing connection objects across threads.
Yes, UniDAC supports OAuth 2.0 authentication when connecting to Salesforce. This modern and secure method can be configured using the SpecificOptions property of the TUniConnection component. To enable OAuth, set the Authentication=atOAuth option. This approach is highly recommended for production environments, as it aligns with Salesforce’s current security best practices.