Skip to content

Instantly share code, notes, and snippets.

View hasanthaera's full-sized avatar

Hasantha Liyanage hasanthaera

  • AMP
  • Melbourne, Victoria, Australia
View GitHub Profile
@hasanthaera
hasanthaera / Class
Created April 23, 2015 06:36
Generic way to update Record Type with a trigger based on a passed value
/**
* getRecordTypeId
* Author: Hasantha Liyanage
* Created: 2014-12-01
* Arguments: sobjectName: the name of the object we want to get the record type for;
* recordTypeName: the name of the record type we want to fetch
* Returns: If found returns the id of the record type, if not returns null. This
* method retrives recordtypes with using metadata.
**/
public static Id getRecordTypeId(String sobjectName, String recordTypeName) {
@hasanthaera
hasanthaera / visualforce page Java script
Created April 23, 2015 06:34
Salesforce - How to call an apex class with java script
// read the parameter values and get the values
var jobId ='{!$CurrentPage.parameters.jobId}';
// pass the values and retrive the URL
var urls = sforce.apex.execute("globalClass","getURL",{jobId:jobId});
document.getElementById("banner").src = urls;
@hasanthaera
hasanthaera / With Regex
Created April 23, 2015 06:33
Validating Record ID : Salesforce
/**
* isValidId
*
* This will check weather the value provided as the ID is exactly
* mathes its format with using regex
*
**/
static public String validateId(String Idparam) {
String id = String.escapeSingleQuotes(Idparam);
if((id.length() == 15 || id.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', id)) {
@hasanthaera
hasanthaera / Update_UserPreferencesHideS1BrowserUI
Created April 23, 2015 06:31
Salesforce - Mass Update saleforce1 mobile field with APEX
/**
* Author: Hasantha Liyanage
* Created: 2014-12-15
* Summary: This will update the UserPreferencesHideS1BrowserUI field and make the Salesforce1 User
* field on User object false
**/
// get the users who does not have salesforce1 mobile feature enabled
List<User> users = [
SELECT
Id,
@hasanthaera
hasanthaera / TestAccountCommon
Created April 23, 2015 06:28
Salesforce - @testsetup method : Spring 15 release
@isTest
public class TestAccountCommon {
// setup test data for entire test methods in teh test class
@testSetup static void setup(){
List<Account> lstAccounts = new List<Account>();
for(integer i = 0;i<5; i++){
lstAccounts.add( new Account(
FirstName = 'Test'+i,
LastName = 'user',
PersonEmail = 'test'+i+'@.com',
@hasanthaera
hasanthaera / compareUtil
Last active August 29, 2015 14:19
Salesforce - compare values through list of objects
List<Sobject> sObjectList = <---provide list of Objects eg: Schools--->
String orderBy = <---provide orderBy field Name eg: School Name--->
String order = <--ASC or DESC--->
List<Sobject> resultList = new List<Sobject>();
Map<object, List<Sobject>> sortMap = new Map<object, List<Sobject>>();
if(sObjectList.isEmpty() || orderBy || order) return;
for(Sobject ob : sObjectList){
if(sortMap.get(ob.get(orderBy)) == null)