Another Salesforce blog!!!

Salesforce, Apex

April, 2017

actionSupport vs actionFunction

. Both actionSupport and actionFunction can be call to an Controller method using an AJAX request. * for example call controller onclick of a inputcheck box * or call a controller method onfocus of a input field Well, they both do the same thing of calling controller method. Difference between both: 1. actionSupport adds AJAX […]

Apex from Custom button or Javascript : Ajax toolkit

Controller: global class myClass { webService static Id makeContact (String lastName, Account a) { Contact c = new Contact(LastName = lastName, AccountId = a.Id); return; } } {!REQUIRESCRIPT(“/soap/ajax/33.0/connection.js”)} {!REQUIRESCRIPT(“/soap/ajax/33.0/apex.js”)} var account = sforce.sObject(“Account”); var id = sforce.apex.execute(“myClass” , “makeContact”, {lastName:”Smith”, a:account}); To call a webService method with no parameters, use {} as the third […]

lock record using SOQL so that it cannot be modified by other user

we will need “FOR UPDATE” clause of SOQL. Account[] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE]; Favorite

SOQL statement can be used to get all records even from recycle bin

We will need “ALL Rows” clause of SOQL. SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS Favorite

enum in APEX

global with sharing class My_Controller { public Case currCase {get; set; } public enum StatusValue {RED, YELLOW, GREEN} public StatusValues getColorStatus() { return StatusValue.RED; //demo code – just return red } } <apex:image url=’stopsign.png’ rendered=”{!colorStatus == StatusValue.RED}” /> Favorite

Custom settings: How to get the data

SO_Country__c code = ISO_Country__c.getInstance(‘name_of_the_custom_settings’); //To return a map of data sets defined for the custom object (all records in the custom object), //you would use: Map<String,ISO_Country__c> mapCodes = ISO_Country__c.getAll(); // display the ISO code for India System.debug(“˜ISO Code: “˜+mapCodes.get(‘name_of_the_custom_settings’).ISO_Code__c); //Alternatively you can return the map as a list: List<String> listCodes = ISO_Country__c.getAll().values(); Favorite

How to get all the required fields of sObject dynamically

There is no direct property available in Apex dynamic API to represent the required field. However there is another way to know about it. If any field have below three properties then it is mandatory field. If it is Creatable If it is not nillable and If it does not have any default value Map<String, […]

get all the fields of sObject using dynamic Apex

Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe(); Schema.SObjectType s = m.get(‘Speaker__c’) ; Schema.DescribeSObjectResult r = s.getDescribe() ; Map<String,Schema.SObjectField> fields = r.fields.getMap() ; system.debug(‘///’ +fields ); Favorite

create instance of sobject dynamically

public SObject getNewSobject(String t) { // Call global describe to get the map of string to token. Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); // Get the token for the sobject based on the type. Schema.SObjectType st = gd.get(t); // Instantiate the sobject from the token. Sobject s = st.newSobject(); return s; } system.debug(‘///’ + getNewSobject(‘Speaker__c’) ); […]

get the list of all available sobject in salesforce database using Apex (Dynamic Apex)

Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ; system.debug(‘///’ + m ); Favorite

Previous Posts