Another Salesforce blog!!!

Salesforce, Apex

July, 2017

sObjectUtils class, utility

global with sharing class sObjectUtils { /** * This method accepts the ID of any object type and returns the full name, including prefix of the sObject * type to which it belongs. * @author cpeterson **/ public static Schema.SObjectType getObjectType(id subject){ Schema.SObjectType result; string target = subject; Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); string keyPrefix; […]

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; }

Check InstanceOf of String or ID

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

Position elements side by side within a single pageBlockSection column

LINK <apex:pageBlockSection title=”Search Payment” columns=”2″ id=”pbs0″> <!–script>twistSection(document.getElementById(“{!$Component.pb0.pbs0}”).childNodes[0].childNodes[0]); </script–> <apex:inputField value=”{!PaymentResponseObj.Source_System__c}” /> <apex:inputField value=”{!PaymentResponseObj.Invoice_Number__c}” /> <!–apex:inputField value=”{!PaymentResponseObj.Invoice_Date__c}” label=”Invoice Date” /–> <!–apex:pageblockSection > <apex:inputField value=”{!PaymentResponseObj.Invoice_Date__c}” label=”From Invoice Date” /> <apex:inputText value=”{!invoiceDateTo}” id=”dateTo” label=”To Invoice Date” onfocus=”DatePicker.pickDate(false, this, false);”> <apex:param value=”{!invoiceDateTo}” /> </apex:inputText> </apex:pageblockSection–> <apex:pageBlockSectionItem> <apex:outputLabel value=”Invoice Date” for=”first” /> <apex:panelGrid columns=”2″> <apex:inputField value=”{!PaymentResponseObj.Invoice_Date__c}” style=”width: 140px;” html-placeholder=”From Invoice […]

creating dropdownlist from custom field in apex

LINK LINK2 List<Payment_Response__c> payResponseList = [select Payee_Country__c from Payment_Response__c] ; List<SelectOption> optionList = new List<SelectOption>(); optionList.add(new SelectOption( ‘ ‘ ,’—Select—‘)); Set<SelectOption> setCountry = new Set<SelectOption>(); for(Payment_Response__c r : payResponseList ) { setCountry.add(new SelectOption(r.Payee_Country__c, r.Payee_Country__c)); //ProductCatalogList1.add(new SelectOption(pc.Category__c,pc.Category__c)); //optionList.add(new SelectOption(u.Id , u.Name)); } optionList.addAll(setCountry); system.debug(‘..’+optionList.size());

add the field api name in ApexPages.StandardController

LINK   public Payment_Response__c PaymentResponseObj {get;set;} public PaymentControllerExt(ApexPages.StandardController stdController) { stdController.addFields(new List<String>{‘Payee_SAP_No__c’, ‘Payee_Country__c’, ‘Invoice_Date__c’, ‘Amount_Currency__c’,stdController.addFields(new List<String>{‘Payee_SAP_No__c’, ‘Payee_Country__c’, ‘Invoice_Date__c’, ‘Amount_Currency__c’,                ‘Amount__c’, ‘WBS__c’, ‘GL_Code__c’, ‘Cost_Center__c’, ‘Company_Code__c’}); this.payReqObject = (Payment_Request__c)stdController.getRecord(); }

Use Set in dynamic SOQL IN-clause in method without Database.query()

public String inClausify(Set<Id> ids) { String inClause = String.format( ‘(\’\'{0}\’\’)’, new List<String> { String.join( new List<Id>(ids) , ‘\’,\”) }); return inClause; } LINK LINK2

get recordtype id, name

SELECT Id, Name, DeveloperName FROM RecordType WHERE SobjectType = ‘obj_name__c’ SELECT Id, RecordtypeId, RecordType.name FROM obj_name__c WHERE Id = ‘012i00000015pm9AAA’

how to get a picklist all values in apex controller

Apex Dynamic PickList values

From the Object Api name retrieving the SObject

 Schema.SObjectType targetType = Schema.getGlobalDescribe().get(sObjectType);   or id myid = ‘a1a0n00000092jb’; String sObjectType = ((Id)myid).getSobjectType().getDescribe().getName(); public void from_string_object_name_to_sObject() { Schema.SObjectType targetType = Schema.getGlobalDescribe().get(sObjectType);//From the Object Api name retrieving the SObject Sobject Object_name = targetType.newSObject(); }

Previous Posts