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

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:

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store