RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!

Upload An Attachment To SalesForce With The Delphi 10.2 Tokyo Enterprise Connectors

I am working on a project that utilizes the Embarcadero Enterprise Connectors powered by CData to access SalesForce through it’s API. The Enterprise Connectors provide you a wide variety of connectors for quickly and easily accessing APIs like SalesForce, Google AdWords, Mailchimp, Facebook, Azure, YouTube, and many many more.

The Enterprise Connectors work through FireDAC and give you an SQL interface to the various APIs that are on offer. This means you don’t have to learn new APIs you simply use standard SQL to access all of the data that you need.

In the case of SalesForce one of the requirements of the project is to upload attachments and attach them to an existing item in SalesForce. I created this function which shows how to do this quickly and easily. SalesForce takes files as a Base6 encoded string so I utilized the System.NetEncoding unit to do this.

There are a number of different ways to write the below code and this is just one way. You’ll have to add your own try..finally or try..except statements to make it more boilerplate.

function TForm1.UploadAttachment(const AObjectId, AFileName: String; ABitmap: TBitmap): String;
SS: TStringStream;
MS: TMemoryStream;
  Result := '';

  MS := TMemoryStream.Create;
  SS := TStringStream.Create;
  MS.Position := 0;
  SS.Position := 0;

  FDQuery1.SQL.Text := 'EXEC CData.Salesforce.UploadAttachment `ObjectId` = :ObjectId, `Base64Data` = :Base64Data, `FileName` = :FileName';
  FDQuery1.ParamByName('ObjectId').AsString := AObjectId;
  FDQuery1.ParamByName('Base64Data').AsMemo := SS.DataString;
  FDQuery1.ParamByName('FileName').AsString := AFileName;
  if FDQuery1.RecordCount>0 then
      Result := FDQuery1.FieldByName('Id').AsString;


Find out more about the Enterprise Connectors and how you can utilize them in your Delphi and C++ apps using FireDAC.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Learn More About Upgrading

About author

FMXExpress.com has over 600 articles with all kinds of tips and tricks for Delphi FireMonkey on Android, IOS, OSX, Windows, and Linux.
Related posts
DatabaseInterBaseRAD Studio

Learn How To Connecing To Local InterBase Instances In This Video

InterBaseNewsRAD Studio

Migrating from BDE/Paradox to InterBase


Get A Visually Stunning FireMonkey App Settings Template For Free Via Embarcadero GetIt


Quick Introduction To FireDAC And Its Features For Building Robust Delphi/C++ Builder Database Applications.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.