Generate QR Code & Save it as Attachment of Record Using Apex and QuickChart API
August 20, 2025
Setup: Add this url in Remote Site Setting
url: https://quickchart.io/
public class QRCodeController {
public static void createQR(){
try{
Account acc=[SELECT Id,Name FROM Account LIMIT 1];
String endpoint = 'https://quickchart.io/chart?cht=qr&chs=300x300&chl=' +EncodingUtil.urlEncode(acc.Name, 'UTF-8');
HttpRequest request = new HttpRequest();
request.setEndpoint(endpoint);
request.setMethod('GET');
Http http=new Http();
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200) {
Blob qrImage = response.getBodyAsBlob();
ContentVersion cv=new ContentVersion(
Title = 'QR Code for ' + acc.Name,
PathOnClient = acc.Name + '_QRCode.jpg',
VersionData = qrImage,
FirstPublishLocationId = acc.Id
);
insert cv;
}
}
catch(Exception e){
System.debug('Error in QRCodeController::'+e.getMessage());
}
}
}
Output:

0
0
votes
Article Rating
Subscribe
Login
0 Comments
Oldest
Newest
Most Voted
Inline Feedbacks
View all comments
Latest Post
About Me
Welcome to an Aimer's weblog :)
Hi! Asif Parvez here, I'm from West Bengal's Howrah. I have extensive experience in Apex, Integration (REST API), LWC, ADMIN and working as Senior Salesforce Developer for Dazeworks Technologies(An iLink Digital Company). I am also a content creator and blogger.
I have three certifications(PD-I, PD-II, Salesforce Associate).
Our Visitor
Our Visitor
0
0
1
1
3
8
Users Today : 1
Users Yesterday : 1
Users Last 7 days : 14
Users Last 30 days : 70
Users This Month : 66
Users This Year : 225
Total Users : 1138
Views Today : 1
Views Yesterday : 2
Views Last 7 days : 16
Views Last 30 days : 113
Views This Month : 108
Views This Year : 346
Total views : 1933
Who's Online : 0
Your IP Address : 216.73.216.134
Server Time : April 30, 2026 1:20 pmPowered By WPS Visitor Counter