Friday, January 3, 2014

Indian Passport Number Validation Rule

Create a custom field in your Object with the name PASSPORT NUMBER.
Paste this validation formula in that Object's Validation rule.


Validation Rule Formula:
NOT( REGEX( PASSPORT_NUMBER__c , "(([a-zA-Z]{1})\\d{7})"))

Validation formula for Indian PAN Card number

Create a custom field in your Object with the name PANCARD.

Paste this validation formula in that Object's Validation rule.

Validation Rule Formula:

NOT( REGEX( PANCARD__c , "((([a-zA-Z]{5})\\d{4})[a-zA-Z]{1})"))

How to compare old values with new values

If you want to compare old account type and new Account type in Account object.
Step 1: Create a new custom field with the name Old Type in Account object. (API name should be Old_Type__c)

Step 2: Paste this code in Account triggers.

Trigger Code:
trigger CheckPreviousAndNewValues on Account (before update)
{
    for (Account Acc : Trigger.old)
    {
        Account OldAcc = Trigger.OldMap.get(Acc.ID);
        if(Acc.Type != OldAcc.Type)
        {
            Acc.Old_Type__c = Acc.Type;
        }
        else
        {
            Acc.Old_Type__c = OldAcc.Type;
        }
    }
}