Tuesday, 7 January 2014

Salesforce: Very useful graphical interface for comparing profiles - Perm Comparator

Navigate to  https://perm-comparator.herokuapp.com where you will be prompted to either sign into your production org or sand sandbox org.



Once signed in you will be presented with this user interface:


This is great because you vary quickly see object permissions/user permissions per user or profile or permission sets and make comparisons.

An excellent way to spot unnecessary permissions.

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.

Friday, 29 November 2013

Salesforce Demo: Cross object formulas - adding lead owner email to lead record

This video shows how to add the lead owners email to the lead record using a cross object formula.



One benefit of doing this is so that you can report on lead owners email (unique field) and potentially saves you using a vlookup command from report export from the user object and lead object.

Some objects support different object types for the Owner field, such as a User, Queue, or Calendar. On objects that support this behavior, when creating a cross-object formula using Owner, you must be explicit about the owner type you’re referencing.

For example, if you need owner email and you don’t use queues, your formula would be Owner:User.Email. If you do use queues, your formula could be:

IF( ISBLANK( Owner:User.Id ), Owner:Queue.QueueEmail, Owner:User.Email )

Here’s how you would select Owner object fields on a Lead in the Advanced formula tab:
Formula Span to Owner

Thursday, 28 November 2013

SOQL Demo: Use Workbench to create a SOQL

Workbench can be used to build SOQL commands.Use this link to sign in to Workbench. You will need to be signed into your Salesforce environment.

Salesforce Object Query Language is very similar to SQL but not as powerful.  It's an easy language to learn.

SOQL uses the SELECT statement combined with filtering statements to return sets of data, which may optionally be ordered:

SELECT one or more fields
FROM an object
WHERE filter statements and, optionally, results are ordered

For example, the following SOQL query returns the value of the Id and Name field for all Account records if the value of Name is Sandy:

SELECT Id, Name
FROM Account
WHERE Name = 'Sandy'

This process is very much like producing a salesforce report but is more time effective way to get the data you need.

Soql Guide

Watch this video:




Upwards traversal - from child to parent - via lookup or master-detail relationship
SELECT Id, Account.Name, Account.Industry, Account.Website
    FROM Contact

    WHERE Account.NumberOfEmployees >= 200

referencing account fields (parent) from contact (child) using dot notation

SELECT Account.Owner.Profile.CreatedBy.Name FROM Contact

You can traverse multiple levels upwards

SELECT Id, customlookupfield__r.customfield__c from contact

Here we’re traversing a custom lookup field customlookupfield__c on the contact object. Notice how the “__c” changes to a “__r” when traversing that field
Downwards traversal - from parent to child - via related list
SELECT Id, Name, Industry, AnnualRevenue,
    ( SELECT Name, Email, BirthDate FROM Contacts )

    FROM Account
nested soql is like another field, nested object uses the plural, (child relationship name found in object settings)

Simple query
SELECT Name FROM Account WHERE Name like 'A%'
SELECT Id FROM Contact WHERE Name LIKE 'A%' AND MailingCity='California'

Query filter on DateTime
SELECT Name FROM Account WHERE CreatedDate > 2011-04-26T10:00:00-08:00
SELECT Name FROM Account WHERE CreatedDate > 2011-04-26T10:00:00Z

Query with Date Function
SELECT Amount FROM Opportunity WHERE CALENDAR_YEAR(CreatedDate) = 2011

Query filter on null 
SELECT AccountId FROM Event WHERE ActivityDate != null

Query Multi-Select Picklists
SELECT Id, MSP1__c from CustObj__c WHERE MSP1__c includes ('AAA;BBB','CCC')
this will return record with MSP__1 example: 'AAA;BBB;DDD' ; 'CCC;EEE'

Semi-Join Query
SELECT Id, Name FROM Account WHERE Id IN ( SELECT AccountId FROM Opportunity WHERE StageName = 'Closed Lost')

Reference Field Semi-Join Query
SELECT Id FROM Task WHERE WhoId IN ( SELECT Id FROM Contact WHERE MailingCity = 'Twin Falls' )

Anti-Join Query
SELECT Id FROM Account WHERE Id NOT IN ( SELECT AccountId FROM Opportunity WHERE IsClosed = false )

Reference Field Anti-Join Query
SELECT Id FROM Opportunity WHERE AccountId NOT IN ( SELECT AccountId FROM Contact WHERE LeadSource = 'Web' )

Multiple Semi-Joins Query
SELECT Id, Name FROM Account WHERE Id IN ( SELECT AccountId FROM Contact WHERE LastName LIKE 'apple%' )
AND Id IN ( SELECT AccountId FROM Opportunity WHERE isClosed = false )

Relationship Query: parent to child
SELECT Id, (SELECT Id from OpportunityLineItems) FROM Opportunity

Relationship Query: child to parent 
SELECT Id, Name, Account.Name FROM Contact

Relationship Query: Polymorphic 
A polymorphic relationship field in object being queried that can reference multiple object types. For example, the What relationship field of an Event could be an Account, or a Campaign, or an Opportunity.
SELECT Id FROM Event WHERE What.TYPE IN ('Account', 'Opportunity')

With OFFSET
Use OFFSET to specify the starting row offset into the result set returned by your query.
SELECT Id, Name FROM Opportunity ORDER BY Name OFFSET 5

With GROUP BY
From API version 18.0 and later, you can use GROUP BY with aggregate functions, such as COUNT(), SUM() or MAX()
SELECT Stagename, COUNT(Id) FROM Opportunity GROUP BY Stagename

SELECT LeadSource, COUNT(Name) FROM Lead GROUP BY LeadSource
SELECT Stagename, SUM(amount) FROM Opportunity GROUP BY Stagename
SELECT CALENDAR_YEAR(CloseDate), COUNT(Id) FROM Opportunity GROUP BY CALENDAR_YEAR(CloseDate) ORDER BY CALENDAR_YEAR(CloseDate)

With GROUP BY ROLLUP
Same with GROUP BY, with additional ROLLUP, it add subtotal for aggregated data in the last row
SELECT Stagename, COUNT(Id) FROM Opportunity GROUP BY ROLLUP(Stagename)


With GROUP BY ROLLUP with 2 fields
SELECT Status, LeadSource, COUNTId) FROM Lead GROUP BY ROLLUP(Status, LeadSource)

HAVING in GROUP BY
You can use a HAVING clause with a GROUP BY clause to filter the results returned by aggregate functions, same with WHERE with normal query
SELECT LeadSource, COUNT(Id) FROM Lead GROUP BY LeadSource HAVING COUNT(Id) > 2

Querying Currency Fields in Multi-currency Organizations
SELECT Id, Name FROM Opportunity WHERE Amount > JPY5000
without currency code it will use organization's default currency

Salesforce Demo: Creating a sales process, record types and a pagelayout

Sometimes it's just much easier to watch the video: