Another Salesforce blog!!!

Salesforce, Apex


Apex – MAP

Adding a key/value to a Map in a standard way: Map intMap = new Map();intMap.put(‘AA’, 100);intMap.put(‘BB’, 200);intMap.put(‘CC’, 300);for (Integer s: intMap.Values()) {system.debug(s);} Map intMap = new Map{‘A’ => 0, ‘b’ => 1,’C’ => 2}; for (Integer s: intMap.Values()) {system.debug(s);} Favorite

using string literals

Literal strings must be enclosed in single quotation marks. double quotation marks are reserved for enclosing attribute values, and must be escaped in strings. Use the “\” character to escape strings. Favorite

Validating an Id length(15 or 18)

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)) { return id; } return null; } Favorite

Check InstanceOf of String or ID

static public Boolean isValidId(String strId) { Boolean isValid = (strId InstanceOf ID) ? true : false ; return isValid ; } Favorite

how to get the RecordType/Id name based on the ID

link question another link id myid = ‘a1aV0000001czYE’; String sObjectType = ((Id)myid).getSobjectType().getDescribe().getName(); private string getRecordTypeId(String objName, String whereClause) { String sqry = ‘ SELECT Id, RecordtypeId, ‘; sqry += ‘ FROM ‘+objName+’ WHERE Id =: whereClause ‘; List<SObject> objs = Database.query(sqry); //system.debug(‘soql: ‘+ objs); string recordTypeId = ”; for(SObject obj : objs) { system.debug(‘soql: […]

How to add a confirm dialog to a command button

<apex:commandButton reRender=”pb” value=”Associate Payment” action=”{!associatePayment}” onclick=”if(!confirm(‘Do you want to proceed?’)){return false};” title=”Associate Payment”/> Favorite

How to get FieldSet fields in Apex Dynamically (fieldset name is not static)

public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName) { Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName); Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe(); //system.debug(‘====>’ + DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName)); Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName); //List<Schema.FieldSetMember> fieldSetMemberList = fieldSetObj.getFields(); //system.debug(‘fieldSetMemberList ====>’ + fieldSetMemberList); return fieldSetObj.getFields(); } You can use result as follows – List<Schema.FieldSetMember> fieldSetMemberList = Util.readFieldSet(‘Account_FieldSet’,’Account’); for(Schema.FieldSetMember fieldSetMemberObj : fieldSetMemberList) { […]

Cloning dynamic in Apex

public with sharing class Utils{ // Returns a dynamic SOQL statement for the whole object, includes only creatable fields since we will be inserting a cloned result of this query public static string getCreatableFieldsSOQL(String objectName, String whereClause){ String selects = ”; if (whereClause == null || whereClause == ”){ return null; } // Get a […]

Apex passing string variable within quotes

String query=’select column_name from information_schema.COLUMNS where table_name =\”+ String.escapeSingleQuotes(selectedValue1)+’\”; Favorite

dynamic apex

PowerPoint DYNAMIC APEX Favorite

Previous Posts