Friday 26 September 2014

Salesforce Custom Label



I have a requirement where I have to display some messages on my visualforce page. I have deal this with apex:pagemessages  if some validation fails and on page with java-script but what will happen if in future I want to change the messages. I don't want to change my code for just some messages.
             To deal with such situation salesforce provides an very useful option "Custom Label". Custom labels are custom text values that can be accessed from Apex classes or Visualforce pages. The values can be translated into any language Salesforce supports. Custom labels enable developers to create multilingual applications by automatically presenting information (for example, help text or error messages) in a user's native language.
                                 
To access Custom Labels go to Setup -> Create -> Custom Labels. This is the best part, Custom Label will be displayed to user depending on their language automatically.  

To refer Custom Label in Visualforce use 
"{$Label.Custom_Label_Name}" 
 Custom Label is one of the Global variable to be used on Visualforce page.

To refer Custom Label in Apex Controller use 
Label .Custom_Label_Name


Note : You can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length.

Where you used your Custom Label ??


Refer: Salesforce

MD5 Hash algorithm



I came to know about a very interesting algorithm MD5 Hash algorithm which is very interesting and would like to share the same with you.

While developing visualforce pages we sometime append the Id to url and use that Id in our controller to fetch the information related to that Id, but what will you do if someone change that Id parameter??

For example I have created a two custom object record and there Id appears for first record as " a0B9000000SFvWK "  and for another " a0B9000000SFvWe ". You will see the Id look similar except last character.

Let us suppose my url for visualforce page looks like :   /apex/customPage?Id=a0B9000000SFvWK
and if I change my url Id parameter from " a0B9000000SFvWK " to " a0B9000000SFvWe " then I can see the content from another record which is not good .

To handle such scenario I use MD5 algorithm.

MD5 stands for Message Digest algorithm 5 which is a cryptographic hash function that was invented by Ronald Rivest . MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity. 
          The idea behind this algorithm is to take up a random data (text or binary) as an input and generate a fixed size “hash value” as the output. The input data can be of any size or length, but the output “hash value” size is always fixed. Whatever the input size you give, the algorithm generates a fixed size (32 digit hex) MD5 hash.

To deal with the above mentioned scenario I have created a new fields which will store the cryptographic hash value which I get populated using the record Id in after insert trigger and use that cryptographic hash parameter instead of record Id, so now anyone who tries to change the url parameter Id will never able to see other record detail .

this is just a small use of MD5 algorithm .
you can try it same if want using below statement in your developer console

String md5Code = EncodingUtil.convertToHex(Crypto.generateDigest('MD5', Blob.valueOf( INPUT STRING ) ));
 

system.debug(md5Code);


How would you use MD5 ????

Reference : Wiki

Thursday 25 September 2014

Credit Card Hidden Information

We use credit/debit card in our daily life. Number printed on our card play a significant role in our transaction but those numbers are not only use for making transaction but also have some hidden information which is helpful to identify if our card is valid or not. I came to know about such information.

Numbers on our card is allocated in accordance with ISO/IEC 7812

1. The first digit of a credit card number is Major Industry Identifier. It identifies the industry within which the card is primarily to be used.



MII digit
Issuer category
0
                          ISO/TC 68 and other industry assignments
1
                     Airlines
2
                     Airlines and other future industry assignments
3
                     Travel and entertainment and banking/financial
4
                     Banking and financial
5
                     Banking and financial
6
                     Merchandising and banking/financial
7
                     Petroleum and other future industry assignments
8
                     Healthcare, telecommunications and other future industry assignments
9
                     For assignment by national standards bodies


2 Issuer identification number (IIN)
The first 6 digits are the Issuer Identification Number also called as "bank identification number" (BIN). It will identify the institution that issued the card. Below are few IINs



Issuing network
IIN ranges
Length
Validation
American Express
34, 37
15
5610, 560221-560225
16
62
16-19
no validation
300-305, 309, 36, 38-39
14
Luhn algorithm
6011, 622126-622925, 644-649, 65
16
Luhn algorithm
5018, 5020, 5038, 5612, 5893, 6304, 6759, 6761, 6762, 6763, 0604, 6390
12-19
51-55
16
4
13, 16
4026, 417500, 4405, 4508, 4844, 4913, 4917
16
Luhn algorithm

 3. Account Number
Take out first 6 and last digit and remaining digit represents account number

4. Check Digit 
last digit in number is considered as Check digit used to validate credit card number. 

refer : http://www.codeproject.com/Tips/515367/Validate-credit-card-number-with-Mod-algorithm

http://money.howstuffworks.com/personal-finance/debt-management/credit-card1.htm