Skip to main content

Generating Barcode image on Visualforce and Formula Field: Salesforce Code Tip

Can we generate bar-code image on Visualforce? Yes, Can we make it a field on page layout? Also yes.
There are many API's available that help us achieve that. One such API is from http://www.searchupc.com. The API is very easy to use.

Visualforce usage:
1. The {!variable} will possibly be the SobjectVariable ({!sobject.fieldname}) or some {!variable} that stores the UPC code(possibly generated from algorithm.)

The output:

Formula Field Usage:
i) Create a formula field with output as 'Text'
ii) Use the below formula, replacing the mergeField with the field you store your UPC number.

image("http://www.searchupc.com/drawupc.aspx?q="+ mergeField ,"Barcode")

The Output:

Works like a charm.

Word of Caution: 
i) The API accepts only 12 and 13 digit of UPC number. Any other digit and it does not render image.
ii) The data is obviously not secure as we are passing the UPC code as a plain text to the server, there is a risk of packet sniffers.

That is it, displaying Barcode on Salesforce. If you find it useful, don't forget to drop in a comment down there, I wouldn't mind if you would prefer putting your name and comment behind a blank cheque and dropping it to my PO box, well, the method below the post seems easy and cheap no?

Comments

Post a Comment

Popular posts from this blog

Video: Top ten tips on how not to ruin Salesforce implementation

Another presentation for the London Salesforce Developer Group using mobile app. 
When it comes to Salesforce development, we all know what it takes to deliver stuff. Having a certified professional helps you gain a knowledgeable partner but what about the things such as common sense?  We all know how to deliver things on client requirements but what about things that are not mentioned by the client. We will be discussing in details things that will enhance the user experience, focus on tips to read your customers mind and have a bit of perspective on the user experience.

Cache me if you can: What you should know before daring to set URL parameter on visualforce

If someone gave me a pence for every time there was an SOQL query in an APEX Class without using Limit or a condition during a code review, I could afford a Lamborgini this month. Sigh. If only. We make it a habit of going digging for data, at the very moment we need it. The crux of this problem happens when you have chain classes which are independent of each other. Each class needs the reference from a single record and we have to query for that record every single time.

While we don't see it, every SOQL query has a cost to it, and it does not go in my Lamborghini fund, however, it should. In a recent project, we had to construct an Account 360 page that could fetch information from different integration points. The page was also called using a live telephony integration, which could pass the phone number for the account. This required an ability to keep in context the Account that was on call.

Passing the Account id in URL parameter was a valid option, however, any manipulatio…

Four secrets to improve the usability of your visualforce/Lightning pages on Salesforce

In the immortal words of a certain machine returning back in time, I am back. For now. After procrastinating for over a year and drafting a lot of rants- I am back with a very important coding lesson for you. For now.

When we are designing a Visualforce page or an app or a lightning component (added that only to trick google) or any web page for that matter, we often tend to wrap up things quickly. Ask anyone on the team, how to design a good User Experience? and the person will immediately throw buzz words like Bootstrap, angular and other useless libraries (did someone squint?)

Ok, Bootstrap, Angular-Js, and all the libraries are really cool and are useful in designing a fabulous UI. They are helpful in creating responsive pages that will work on all the devices but this post is not about those. Nope. For the purpose of this post, all the external libraries and buzzwords you use to decorate your resume are useless. (Adding Angular JS in your resume for a Salesforce consultant posit…