Have an amazing solution built in RAD Studio? Let us know. 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.


What's New for RAD Studio 11

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

   Free Delphi Community Edition   Free C++Builder Community Edition

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
CodeDelphiRAD Studio

This Is How To Easily Process CSV Data Using FireDAC


This Week's New C++ Post Picks From LearnCPlusPlus.org

CodeDatabaseDelphiRAD Studio

6 Easy Ways to Connect to the Top Databases You Should Know

C++DelphiIDERAD Studio

My 7 Favorite Software Development Productivity Tools

Leave a Reply

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