Showing posts with label developer. Show all posts
Showing posts with label developer. Show all posts

Wednesday 9 October 2013

Describe all the fields for all SObjects

13:58
In one of the requirements I came across, I needed to get the list of all the fields across all objects. I wanted to make sure that I did in the best possible way, But couldn't find any straight answers. So here's the code I came up with. Its simple and straight-forward and if you find a better way to do this let me know in the comments. Thank you

To start off, we need the list of SObjects that we are going to run this for. Ideally we should have the list of SObjects stored in a Custom setting, this is a one time thing and could be done using anonymous apex execution. Following is the code to do just that..

List<string> SObjectList = new List<string>();

for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
   String name = objTyp.getDescribe().getName();
   // Exclude all the unwanted Sobjects e.g. History, Share etc..

 if(!name.containsignorecase('history') && !name.containsignorecase('tag')&&
    !name.containsignorecase('share') && !name.containsignorecase('feed')){      
      SobjectList.add(name);
  }
   // Insert into your custom settings
  }
Now that we've got the entire list of SObjects, lets do a Global Describe. Before we move on there is a gotcha here, as you know there is a governor limit on the number of Describes in an execution context (As of Winter '14 its 100 in both asynchronous and Synchronous) . I'll go ahead and suggest that its best if you could either do it in multiple executions or use a limit to control the number of SObjects processed.

 
      SObjectFieldsMap = new Map<string,Set<string>> ();
      Map<String, Schema.SObjectType> GlobalDescribe = new Map<String, Schema.SObjectType>();
      // Get the Global Describe which contains details for all objects
      GlobalDescribe =Schema.getGlobalDescribe();

      // Now we loop through our pre-compiled list of SObjects and get the describes for it
      for(String sObj:SObjectList)
      {
       // Populate the Map, with Sobject => list of fields
       if(SObjectFieldsMap.get(Sobj)==null && GlobalDescribe.get(sObj)!=null)
        SObjectFieldsMap.put(sObj,new Set<string>());

        if(SObjectFieldsMap.get(sObj)!=null) // Some Objects may not have Describes 
        SObjectFieldsMap.get(sObj).addAll(GlobalDescribe.get(sObj).getDescribe().fields.getMap().keyset());
      }
      
Well thats pretty much it. Hope this helps, let me know if you need anymore clarifications on this or if you've got some thoughts on this. Happy Coding!

Wednesday 24 April 2013

How to activate Summer ’13 Preview on sandbox

10:18
Summer 13The salesforce.com Summer ‘13 release is quickly approaching and soon you'll be able to take advantage of exciting new features and functionality! If you are a Force.com Sandbox customer, you have the opportunity to get early access to Summer ‘13 in your Sandbox and test new customization and features (the chance to get your feet wet) before your production organization is upgraded.




Tuesday 9 April 2013

Second Meetup in Cochin announced- Salesforce.com Kerala User Group

23:03



The Salesforce Kerala User Group- the official meeting point of Force.com enthusiasts in Kerala and around is thrilled to announce its second Meetup event to be held on April 11th, 2013 at the IMA Hall, Palarivattom, Cochin. A sequel to the Meetup in October which was the first of its kind in Kerala, the upcoming one has an agenda designed to take you a step higher. This is a great platform for any and every one of you with a link to the ‘cloud’ to get together and swap ideas, share your experiences and learn about exciting new trends in the market today.

Thursday 14 March 2013

Visualforce To Excel

02:11
In this short post I want to explain how we can generate an excel output from a VF page.  We already know to how to generate a PDF from VF page. (Read more to find out how). One of the common requirements is to convert a VF page with data into an Excel sheet, here are some things you may want to keep in mind
  1. Use a separate VF page for export. It is advisable to use a separate VF page to export off, reason being, usually the VF page in which data resides contains buttons, links images etc. and that is not something you usually want in your excel
  2. Use <apex:dataTable> : this gives you a consistent output and works for both windows and MAC. (Thank you Pratyush Kumar  for the Info)
  3. Proper validation : Before the export page is reached, make sure all validations to ensure data will be present is  a good practice

Thursday 31 January 2013

Spring ‘13 Release Rituals

11:50

The much awaited Spring ‘13 webinar was yesterday 30-JAN-2013. It was exciting and thanks to Pat Paterson(@metadaddy) and Samantha (@samantha_ready) for the amazing webinar presentation which covered the thrilling topics of spring 13 like
          • Tooling API, 
          • Connect in Apex,
          •  Canvas 
          •  Connected apps.

Tuesday 8 January 2013

Spring ‘13 Features Release Preview

01:09

spring13Salesforce.com Spring ‘13 is a debated release where some say there are not many features being released like the usual salesforce releases while some say that Spring ‘13 packs really good and needed features. I’ll let you be the judge of that.
All of what I can say is , it is exciting as we are all waiting to see what is packed in this release and can’t wait to get our hands on it. Below are the videos salesforce released on their YouTube channel some time ago.
you can also find the release notes here : http://shivd.me/Spring13Release
The Spring 13 Release Preview of all features : http://shivd.me/Spring13ReleasePreview
and you could join us for the webinar here: http://shivd.me/Spring13Webinar
You could sign up for the Pre-Release ORG here : http://bit.ly/getspring13

Sunday 6 January 2013

Run Batch Class Hourly

16:34
This is a use case that we all come across very often, Schedule a batch class every hour to clean up data or to send out batch emails to case team members (Which I’ll blog about later).
There are three main steps involved in this
  1. Write a Batch class with the required logic
  2. Write a Scheduled Apex which calls the above Batch Class
  3. Schedule the class from the developer console by executing anonymous apex