How to generate a QR code barcode as a PNG file in Salesforce Apex

Cloudmersive
1 min readFeb 16, 2020

--

Today’s lesson: generating QR codes in Apex. Sound difficult? Normally yes, but we’ve got a nice shortcut for you today. You won’t believe how easy it is.

First we download the Cloudmersive API client and copy the folder within to our project directory.

So far so easy. Now input your desired string into generateBarcodeQRCode:

SwagGenerateBarcodeApi api = new SwagGenerateBarcodeApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'value' => 'value_example'};try {// cross your fingersBlob result = api.generateBarcodeQRCode(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

That’s it! Here is a sample QR code for the phrase “APIs are the best!” made with this function:

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet