Quick and easy way to convert a List<sObject> to Set<Id>

A quick and efficient way to convert a list of sObject’s into a Set of Id’s.


List<Id,Account> accountList = new List<Id,Account>();
accountList = [SELECT Id, Name FROM Account WHERE Name LIKE 'A%'];

//Convert list to Set of Ids.
Set<Id> accountdIds = (new Map<Id,Account>(accountList)).keySet();

Refresh Detail Page Fields from Custom Quick Action

If you want to update information displayed on the detail page or the feed view on an object after updating the record from a custom quick action visualforce page, then you can you the below snippet which uses the Canvas / Publisher API.

//Publisher JS Library
<apex:includeScript value="/canvas/sdk/js/publisher.js" />

//Action Function
<apex:actionFunction name="executeUpdate" action="{!updateCaseClassification}" oncomplete="refreshFeed();">

function refreshFeed() 
{
    Sfdc.canvas.publisher.publish(
    { 
        name : 'publisher.refresh', 
        payload : { 
            feed: true, 
            objectFields: true
        }
    });
}

Salesforce Web-to-lead reCAPTCHA Key – Insufficient Privileges

If you receive an “Insufficient Privileges” message when trying to add a new reCAPTCHA Key Entry on the Web-to-lead OR Web-to-case generator page within Salesforce you can use the below steps to fix this:

To Enable, please follow below steps:

1. Click Setup
2. Click Customize
3. Click User Interface
4. Enable Show Quick Create
5. Click Save

After this, go back and add the new reCAPTCHA API Key Pair:

1. Click Setup
2. Click Customize
3. Click Leads | Select “Web-to-Lead”
2. Click Create Web-to-Lead form
3. Enable Spam Filtering
4. Click reCAPTCHA API Key Pair Lookup button
5. Click New | fill out Required fields
6. Click Save

Validate An ID Field Format

There may be times where you would like to valid if an sObject ID is valid.    A good use case would be when an ID is passed as a URL parameter to a visualforce page.   The below method can be used to check this.

 /**
 * Validates an ID passed.
 **/ 
 public Boolean validId(String inputId) {
 String id = String.escapeSingleQuotes(inputId);
 if((id.length() == 15 || id.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', id)) {
 return true;
 }
 return false;
 }

Custom Cancel Button Action

Sometimes you may not be able to use the standard controller “cancel” page action, so you can easily replicate the behavior using the below snippet.  This will return the person to the object record.

Visualforce Code:

<apex:commandButton action="{!actionCancel}" value="Cancel"/>

Apex Code:

public PageReference actionCancel() { 
    PageReference page = new PageReference('/'+objectRecord.Id);
    page.setRedirect(true);
    return page;
}

 

Salesforce Developer Console Shortcut

A quick time saver to launch the Developer Console from a Chrome bookmark page.   You just need to ensure that you are on a Salesforce page when clicking the bookmark as it uses the active pages instance URL for the Developer Console URL construction.

Here is the code for the bookmark page:

javascript: var url = window.location.protocol+'//'+window.location.hostname+'/_ui/common/apex/debug/ApexCSIPage'; window.open(url, "_blank");