Saturday, July 13, 2019

How to display Map values on Visualforce Page ?

Below code will to get map value in to VF page

public class ToolController {
    public Map toolMap { get; set; }
    public String myKey  { get; set; }

    public ToolController() {
        Map toolsMap = new Map();
        toolsMap.put('Stapler', 'Keeps things organized');
    }
}

   
   

How to get object name from id value in salesforce

Hi with the help of below code, we can find objec name by salesforce RecordID

(1)
Id someId = '00590000000eF8z';
System.debug(someId.getSObjectType());

(2)
public string findObjectAPIName( String recordId ){
        if(recordId == null)
            return null;
        String objectAPIName = '';
        keyPrefix = recordId.substring(0,3);
         for( Schema.SObjectType obj : Schema.getGlobalDescribe().Values() ){
              String prefix = obj.getDescribe().getKeyPrefix();
               if(prefix == keyPrefix){
                         objectAPIName = obj.getDescribe().getName();
                          break;
                }
         }

         return objectAPIName;

}

How to dynamically determine Calling Context using Apex in Salesforce?

Hi All ,

we are using the multiple feature and Context (type) as per our requirement while writing Apex code.

Sample are:-

  • Batch
  • @future 
  • Queueable 
  • Schedulable 
  • Trigger 
  • Visualforce 
  • Apex REST 

so we can identify these context item in Apex code  as give way:-


  •  Batch - System.isBatch()
  • @future - System.isFuture()
  • Queueable - System.isQueueable()
  • Schedulable - System.isScheduled()
  • Trigger - Trigger.isExecuting
  • Visualforce - ApexPages.currentPage() != null
  • Apex REST - RestContext.request != null

Getting picklist field options in list in apex classs

Display pick list values in your custom page through dyanamic apex .You can check below link it will help  .

https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html

If you want in a string array or list then you can use below code .

public List getPickListValuesIntoList(){
       List pickListValuesList= new List();
  Schema.DescribeFieldResult fieldResult = ObjectApiName.FieldApiName.getDescribe();
  List ple = fieldResult.getPicklistValues();
  for( Schema.PicklistEntry pickListVal : ple){
   pickListValuesList.add(pickListVal.getLabel());
  }     
  return pickListValuesList;
    }