Another Salesforce blog!!!

Salesforce, Apex

June, 2017

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, RecordType.name ‘; 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”/>

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) { […]

Execute JavaScript in Salesforce

/* * Description: Javascript for Reject_RAE button. * Created by : * Author : */ {!REQUIRESCRIPT(“/soap/ajax/23.0/connection.js”)} {!REQUIRESCRIPT(“/soap/ajax/23.0/apex.js”)} //check if Contact id is same as RAE Id var recId = ‘{!Event__c.Id}’; var status = ‘{!Event__c.Status__c}’; if(“{!Event__c.RAEId__c}” == “{!$User.ContactId}”){ var validateComplete = sforce.apex.execute(‘OUS_GlobalUtilCls’, ‘validateEventCompletionWS’,{eventId:recId}); if(validateComplete == ‘{!$Label.Amg_Result_Code_All_OK}’){ var clickRes = confirm(‘{!$Label.OUS_Event_Complete_Msg_4}’); if (clickRes == true) { window.location.href […]

apex:inputTextarea – required

<apex:pageBlockSection columns=”2″> <apex:PageBlockSectionItem > <apex:outputlabel value=”Amendment Justification”/> <apex:outputPanel styleClass=”requiredInput” layout=”block”> <apex:outputPanel styleClass=”requiredBlock1″ layout=”block”/> <apex:inputTextarea value=”{!o_req[‘Amendment_Justification__c’]}” cols=”70″ rows=”4″ required=”false” label=”Amendment Justification” /> </apex:outputPanel> </apex:PageBlockSectionItem> </apex:pageBlockSection>

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)+’\”;

Required InputTextArea

I was asked to make an inputtextarea required on a visualforce page and thought, “ok, no problem, 2 minutes!”. In reality, this was kind of a nightmare to implement. My vf page looked something like this: <apex:pageblock id=”pageBlock”> <apex: pagblocksection id=”pageBlockSec”> <apex:pageblocksectionitem> <apex:outputlabel value=”Big Field”> <apex:inputtextarea value=”{!myObject__c.Big_Field__c}” required = true id=”bigfield”}” … So the first […]