Sunday 15 December 2013

Salesforce: Validation Rules

Validation rules verify the data entered into fields is of the correct data type and meets the standards you set before a record can be saved.

You can use boolean formulas that evaluates the field data and results in true/false statements.


You also have to specify an error message if the user breaks a validation rule on save due to an invalid value.


Salesforce processes rules in the following order:

  1. Validation rules
  2. Assignment rules
  3. Auto-response rules
  4. Workflow rules (with workflow actions)
  5. Escalation rules

Also:
  • When one validation rule fails, Salesforce continues to check any additional validation rules on that field or any other field on the page and displays all appropriate error messages at once.
  • If validation rules exist for activities and you create an activity during lead conversion, the lead converts but a task isn’t created.
  • Validation rules are only enforced during lead conversion if validation and triggers for lead conversion are enabled in your organization.
  • Campaign hierarchies ignore validation rules.
  • Salesforce runs validation rules before creating records submitted via Web-to-Lead and Web-to-Case, and only creates records that have valid values.
  • Validation rules continue to run on individual records if the owner is changed. If the Mass Transfer tool is used to change the ownership of multiple records, however, validation rules won’t run on those records.

How to create a validation rule:

  1. Navigate to the relevant object, field, campaign member, or case milestone.
  2. In the Validation Rules related list, click New.
  3. Enter the properties of your validation rule.
  4. To check your formula for errors, click Check Syntax.
  5. Click Save to finish or Save & New to create additional validation rules.

Example Validations:


Validates that the account Billing Zip/Postal Code is in the correct format if Billing Country is Canada.
AND(OR(BillingCountry = "CAN", BillingCountry = "CA", BillingCountry = "Canada"),
NOT(REGEX(BillingPostalCode, "((?i)[ABCEGHJKLMNPRSTVXY]\\d[A-Z]?\\s?\\d[A-Z]\\d)?"))
)

Validates that the account Billing Zip/Postal Code is valid by looking up the first five characters of the value in a custom object called Zip_Code__c that contains a record for every valid zip code in the US. If the zip code is not found in the Zip_Code__c object, or the Billing State does not match the corresponding State_Code__c in the Zip_Code__c object, an error is displayed.

VLOOKUP(
$ObjectType.Zip_Code__c.Fields.City__c ,
$ObjectType.Zip_Code__c.Fields.Name ,
LEFT(BillingPostalCode,5)) <> BillingCity

Validates that the account Billing Zip/Postal Code is in 99999 or 99999-9999 format if Billing Country is USA or US.AND(
OR(BillingCountry = "USA", BillingCountry = "US"),
NOT(REGEX(BillingPostalCode, "\\d{5}(-\\d{4})?"))
)

Validates that the Account Number is numeric if not blank. AND(
   ISBLANK(AccountNumber),
   NOT(ISNUMBER(AccountNumber))
)

Validates that the Account Number is exactly seven digits (if it is not blank). The number seven is simply illustrative.AND(
   ISBLANK(AccountNumber),
   LEN(AccountNumber) <> 7
)

Validates that a custom field called Hours Worked is not a negative number
Hours_Worked__c < 0Validates that the contact Mailing StreetMailing City, and Mailing Country are provided.OR(   ISBLANK( MailingStreet ),
   ISBLANK( MailingCity ),
   ISBLANK( MailingCountry )
)

Validates that the value of a custom date field is a weekday (not Saturday or Sunday).
CASE(MOD( My_Date__c - DATE(1900, 1, 7), 7),
0, 0,
6, 0,
1) = 0






Friday 6 December 2013

Visualforce: Overriding an Existing Page with a Visualforce Page

Make each section for an account display in a tab, such as contacts, opportunities

Create a Visualforce page:
goto setup - develop - pages - new
type tabbedaccount for the label and name for the page and then copy this code:

<apex:page standardController="Account" showHeader="true" 
      tabStyle="account" >
   <style>
      .activeTab {background-color: #236FBD; color:white; 
         background-image:none}
      .inactiveTab { background-color: lightgrey; color:black; 
         background-image:none}
   </style>
   <apex:tabPanel switchType="client" selectedTab="tabdetails" 
                  id="AccountTabPanel" tabClass='activeTab' 
                  inactiveTabClass='inactiveTab'>   
      <apex:tab label="Details" name="AccDetails" id="tabdetails">
         <apex:detail relatedList="false" title="true"/>
      </apex:tab>
      <apex:tab label="Contacts" name="Contacts" id="tabContact">
         <apex:relatedList subject="{!account}" list="contacts" />
      </apex:tab>
      <apex:tab label="Opportunities" name="Opportunities" 
                id="tabOpp">
         <apex:relatedList subject="{!account}" 
                           list="opportunities" />
      </apex:tab>
      <apex:tab label="Open Activities" name="OpenActivities" 
                id="tabOpenAct">
         <apex:relatedList subject="{!account}" 
                           list="OpenActivities" />
      </apex:tab>
      <apex:tab label="Notes and Attachments" 
                name="NotesAndAttachments" id="tabNoteAtt">
         <apex:relatedList subject="{!account}" 
                           list="CombinedAttachments" />
      </apex:tab>
   </apex:tabPanel>
</apex:page>

Now that you've created a page to display an account with tabs, you can use this page to override the detail view for all accounts.
From Setup, click Customize | Accounts | Buttons, Links, and Actions.
Click Edit next to View.
For Override With select Visualforce Page.
From the Visualforce Page drop-down list, select tabbedAccount.
Click Save.
Click the Account tab, and select any account. The detail for the account is now displayed with tabs.

Monday 2 December 2013

Apex - Setting up Eclipse

There are 4 steps to setting up Eclipse to work with Salesforce:

  • INSTALL JAVA
  • DOWNLOAD ECLIPSE
  • INSTALL FORCE.COM IDE PLUGIN FOR ECLIPSE
  • CONFIGURING ECLIPSE WITH YOUR ORG

INSTALL JAVA
Eclipse was originally written for the Java platform. It still requires a Java Runtime Environment (JRE) or a Java Development Kit (JDK)

DOWNLOAD ECLIPSE:
Eclipse is modular software. The link is: Download Eclipse Standard 4.3.1 here

The file is about 199 MB in size, so it will take a while to download. You will end up with a .ZIP file. Unpack the file. Move the unpacked folder to  c:\eclipse. You can now start Eclipse by double-clicking it.


FORCE.COM IDE ECLIPSE PLUGIN INSTALL:
Now log into your salesforce org and goto setup - develop - tools and download force.com ide plugin for eclipse:



Copy the entire contents of the plugin folder from the force.com IDE plugin download into the plugins folder of the eclipse folder at c:\eclipse\plugins

Now follow these steps


  1. Launch Eclipse and click Help > Install New Software

    Install New Software

  2. Click Add....
  3. In the Add Repository dialog, set the Name to "Force.com IDE" and the Location to "http://media.developerforce.com/force-ide/eclipse42" and click OK. (Use the same URL for Eclipse 4.3.)

    Add Site

  4. Eclipse downloads the list of available plugins and displays them in the Available Software dialog.
  5. Check the box next to the Force.com IDE plugin and click Next.

    Select Force.com IDE plugin

  6. In the Install Details dialog, click Next.
  7. In the Review Licenses dialog, accept the terms and click Finish.
  8. Eclipse downloads and installs the Force.com IDE and any required dependencies. When installation is complete, you will be prompted to restart. Click Yes.
  9. When Eclipse restarts, select Window > Open Perspective > Other, select Force.com and click OK.

note you may prefer this:
  1. Launch Eclipse and select Help | Install New Software.
  2. Click Add.
  3. In the Add Repository dialog, set the name to Force.com IDE and the location tohttps://developer.salesforce.com/media/force-ide/eclipse45. For Spring ’16 (Force.com IDE v36.0) and earlier Force.com IDE versions, use http://media.developerforce.com/force-ide/eclipse42.
  4. Click OK.
  5. To install an older version of the plug-in (for example, if you don’t have Java 8), deselect Show only the latest versions of available software.
    Eclipse downloads the list of available plug-ins and displays them in the Available Software dialog.
  6. Select the Force.com IDE plug-in, and then click Next.
  7. In the Install Details dialog, click Next.
  8. In the Review Licenses dialog, accept the terms and click Finish.
  9. If you choose to install support for Lightning components, Eclipse displays a warning dialog about installing software that contains unsigned content. We are bundling third-party plug-ins to support Lightning components. Salesforce doesn’t own these third-party plug-ins; hence, we don’t sign them. Click OK to proceed.
  10. Eclipse downloads and installs the Force.com IDE and the required dependencies. When the installation is complete, you are prompted to restart. Click Yes.
  11. When Eclipse restarts, select Window | Open Perspective | Other. Select Force.com and then click OK.
    You are now ready to develop and customize Force.com applications in Eclipse!

CONFIGURING ECLIPSE WITH YOUR ORG

To create a new project in eclipse, click file - new.  
you will be prompted to login to your org and create a project name:

You can now choose to download all or some of the metadata already in your org



TIP - before  logging into your org  from Eclipse,  enter the IP of your PC into Salesforce Setup - Security Controls - Network Access.  You can find your IP by using ipconfig/all in the command prompt.