Wednesday, 16 December 2015

Salesforce Certified Developer - Winter '16 Release Exam


Salesforce Certified Administrator - Winter '16 Release Exam


Monday, 4 August 2014



Salesforce Article Management:  Get DataCategories from DataCategoryName for 'Knowledge Articles'


v Create DataCategory for Articles:
        
Setup è Knowledge è Data Category
                       
Crate new Data Category, named ‘SampleDataCategoryName’.

v Create DataCategoryValues and Map to DataCategory:
           
Setup è Knowledge è Data Category Assignment
                       
Add SampleDataCategoryNames to SampleDataCategoryName.

For example: SampleDataCategoryName1, SampleDataCategoryName2, SampleDataCategoryName3

v Requirement:
                       
There are scenarios where we need to fetch all assigned DataCategory values based on particular DataCategoryName.

Below is the  apex code to get all assigned DataCategory values based on DataCategoryName as 'SampleDataCategoryName'.
                       
String dataCategoryGroupName = 'SampleDataCategoryName';

//variable declaration

DataCategory [] toplevelCategories;
DataCategory [] childCategories;     
List<String>dataCategoriesValues = new List<String>();       
List<DataCategoryGroupSobjectTypePair> pairs = new List<DataCategoryGroupSobjectTypePair>();      
DataCategoryGroupSobjectTypePair pairObj = new DataCategoryGroupSobjectTypePair();
         
pairObj.setSobject('KnowledgeArticleVersion');
pairObj.setDataCategoryGroupName(dataCategoryGroupName);
pairs.add(pairObj);    
                  
List<DescribeDataCategoryGroupStructureResult> describeCategoryStructureResult = Schema.describeDataCategoryGroupStructures(pairs, false);
         
for(DescribeDataCategoryGroupStructureResult result1 : describeCategoryStructureResult){
     toplevelCategories = result1.getTopCategories();
}
         
for(DataCategory result2 : toplevelCategories){
     childCategories = result2.getChildCategories();
}
         
for(DataCategory result3 : childCategories){
     dataCategoriesValues.add(result3.getLabel());
}
         
system.debug('dataCategoriesValues==>'+dataCategoriesValues);    
         

// Output is:  dataCategoriesValues==> SampleDataCategoryName1 , // SampleDataCategoryName2 , SampleDataCategoryName3 '       

Tuesday, 13 March 2012

Find 'Day' & ‘Day Of Week’ From 'Date' in Salesforce.

There are many scenarios in salesforce where we need to find out day from date.
For example, for scheduling a job through system.schedule() method , we need  Day_of_week.





Date startDate = date.newInstance(0001, 1, 1);

List<String> daysList = new List<String>
{'null', 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday','Saturday' }; 


Date dayForDate = system.today();

Integer remainder = Math.mod(startDate.daysBetween (dayForDate) , 7);
       

if(remainder==0){remainder=7;}
       

string calculatedDay = daysList.get(remainder);

system.debug('Day of week for dayForDate ---->'+remainder);


system.debug('day for dayForDate ----->'+ calculatedDay);

Tuesday, 21 February 2012

Get sObject Name from Record ID.....!!!!

Sometimes there are scenarios when we use

string urlID = ApexPages.currentPage().getParameters().get('id');

and develop the functionality based on urlID .

What should we do, if sometimes urlID gives ID of Object 'X' and sometimes it gives
ID of 'Y' based on business requirement?

Here is what I did....






 urlId=ApexPages.currentPage().getParameters().get('id');

 Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
            
 Map<String,String> keyPrefixMap = new Map<String,String>{};
            
 Set<String> keyPrefixSet = gd.keySet();
           
 for(String sObj : keyPrefixSet){
               
 Schema.DescribeSObjectResult r =  gd.get(sObj).getDescribe();
               
 String tempName = r.getName();             
               
 String tempPrefix = r.getKeyPrefix();
              
 keyPrefixMap.put(tempPrefix,tempName);
             
 }
            
             
 string objtempPrefix =urlId.subString(0,3);
             
 string objname =keyPrefixMap.get(objtempPrefix );
         
             
 system.debug('object name--------------->'+objname );




The first three chars of a record id refer to the sobject the record is based on.
 IF urlId is ID of X , objname will be 'X'
 IF urlId is ID of Y , objname will be 'y'