Showing posts with label Forcedotcom. Show all posts
Showing posts with label Forcedotcom. Show all posts

Aug 23, 2012

Salesforce Platform Developer User Group

Recently Salesforce took an initiative to start developer user groups in India. The goal of developer user group program is to build an enthusiastic, self-sustaining community that enables members to be more successful with Salesforce, and helps to build an army of heroes willing to give testimony to success in the cloud.

Journey begins with New Delhi Salesforce Platform Developer Meetup where I was invited as a guest speaker. There I met "Kavindra Patel" who is behind all this, developer relationship manager at Salesforce. His mindset was very clear and focused on how to get the ball rolling.

I requested him to start a meetup in Jaipur and the immediate words from him was "Go Big". After New Delhi Salesforce organized Developer Hands-On Workshop in Hyderabad, Pune and Bangalore. From there Kavindra pick 8-9 leaders from different regions of India to start the Developer User Group. Here is the complete list, please join the group which is near to your place.

Now it's turn of Jaipur Salesforce Platform Developer User Group Meetup. Luckily am the leader of this group and would request all who are near by Jaipur to join this group. Our inaugural meeting is on 2nd Sept 2012, please RSVP here. There are some awesome technical sessions lined up like "Heroku, Ruby and Force.com Integration" and "Streaming APIs Working Demo". You can get the complete agenda from here. Also join us on LinkedIn, Facebook and Meetup for updates.

Thanks to Kavindra Patel and April Kyle Nassi who helped me to setup a meetup account and will be sending awesome goodies (Caps,T-Shirts,Books etc..) for Cloud Trivia.

Also would like to thank my speakers in inaugural meetup Amit Jain and Deepak Raj. They are also helping me to organize the event, and their contribution is appreciable.

Jul 30, 2012

Is There Better Way To Get Last Date Of Fiscal Quarter?

Recently it was requested to get the "Last Date" of present Fiscal Quarter. For e.g. if "Fiscal Year Start Month" is set to January (Setup > Administration Setup > Company Profile > Fiscal Year) and present month is Feb then date returned should be "31 March 2012"


SOQL is not the option as in the end I need to get the Date so after lot of brain storming end up with this solution, if this is not the best solution then other solutions suggestions are most welcomed.


So here is my apex method which returns me the last date of present fiscal quarter


//Returns last date of present fiscal quarter
public Date LastDateofCurrentFQ()
    {
        // Info : There are 4 Fiscal Quarter FQ( each of 3 months) in fiscal year 
        Organization  org = new Organization() ;
        org = [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()];
        Integer FiscalYearStartMonthIndex = org.FiscalYearStartMonth ; 

        // Month Index like january : 1 , february: 2 and so on 
        Integer CurrentMonthIndex = system.today().month();

        if(CurrentMonthIndex < FiscalYearStartMonthIndex )
            CurrentMonthIndex  = 12+ CurrentMonthIndex ;

        Integer DifferenceofBothMonths = CurrentMonthIndex - FiscalYearStartMonthIndex  ;
        Integer CurrentFiscalQuarterLastMonth  = 0; 

 if(0 < = DifferenceofBothMonths && DifferenceofBothMonths <= 2 ) //For first quarter
            CurrentFiscalQuarterLastMonth = FiscalYearStartMonthIndex  +2 ; 
        else if( 3 <= DifferenceofBothMonths && DifferenceofBothMonths <= 5) //For second quarter 
            CurrentFiscalQuarterLastMonth = FiscalYearStartMonthIndex  +5 ;
        else if( 6 <= DifferenceofBothMonths && DifferenceofBothMonths <= 8) // For third quarter
            CurrentFiscalQuarterLastMonth = FiscalYearStartMonthIndex  +8 ;
        else if( 9 <= DifferenceofBothMonths && DifferenceofBothMonths <= 11) // For fourth quarter
            CurrentFiscalQuarterLastMonth = FiscalYearStartMonthIndex  +11 ;

        if(CurrentFiscalQuarterLastMonth > 12)
            CurrentFiscalQuarterLastMonth  = CurrentFiscalQuarterLastMonth  - 12 ;         

        Date firstDateOFyear = date.newInstance(system.today().year(), 1, 1);
        Date LastDateofCurrentFQ  = date.newInstance(system.today().year(), 1, 1); 
        LastDateofCurrentFQ   = firstDateOFyear.addMonths(CurrentFiscalQuarterLastMonth).addDays(-1) ;
        return LastDateofCurrentFQ ;        
    }

Code is self explanatory, still if anything is not clear do reach me out.

New Delhi Salesforce Platform Developer User Group Meetup — My Experience

My experience from inaugural Salesforce Platform Developer User Group Meetup held in Noida (New Delhi) - on SFDC blogs:


http://blogs.developerforce.com/developer-relations/2012/07/new-delhi-salesforce-platform-developer-user-group-meetup.html

Will be organizing Salesforce Platform User Group in Jaipur, please join LinkedIn group for more updates.

http://www.linkedin.com/groups/Salesforce-Platform-Developer-User-Group-4538959

Jul 27, 2012

Please Remove The System Objects From My sObject List

Question is "Can I remove the system objects from list returned by describe?"

I need to identify on which all objects I can create approval process. First and only thought is to use describe and get the list of sObjects, but the problem is describe returns too many other objects on which we can not create approval process like "campaignfeed", "caseteamrole" etc.. So what is the use of showing them all. Why not we can show the list of only those object which are displayed when we create approval from native UI?



Here is the solution for this big time problem. Use this apex code to get the sObject List (use describe in a smart way)

public class ApprovalEnabledObjectsController
{
    //List displayed on UI
    public List<selectoption> supportedObject {get; set;}
    
    //Constructor
    public ApprovalEnabledObjectsController()
    {
        //Initialize
        supportedObject = new List<selectoption>() ;
        
        //Get only reference to objects
        for(Schema.SObjectType item : ProcessInstance.TargetObjectId.getDescribe().getReferenceTo())
        {
            //Excluding custom setting objects
            if(!item.getDescribe().CustomSetting)
            {
                //Adding to list
                supportedObject.add(new SelectOption(item.getDescribe().getLocalName().toLowerCase() , item.getDescribe().getLabel() ));
            }
        }
        
    }
}


Visualforce Page (Test page to show the picklsit)



    
        
    




Special thanks to Amit Jain who helped me with this :-)

May 30, 2012

Update Record From Formula Field

Recently an interesting implementation forced me to write this post, and may be many of you are already aware of this. There is a related list where I need to show a formula field, and on click of that field I need to change the status of that record.

Say case is related to account, and they are displayed in a related list on account. Now I want to change the status of any case which is related to an account. One way is to click on the case "edit", change the status and save it. I don't want to do this as it takes time and more button clicks. Another way is to provide a formula field as a hyperlink, and when that link is clicked status should be changed.

So for this create a formula field on Case ("UpdateStatus" for the reference) which will be a hyperlink and it will execute an visualforce page like this :

HYPERLINK("/apex/UpdateStatus?RecId=" + Id ,"Click To Change Status","_top")


Now add this formula field in case related list on account page layout, like this :



Now it's time to write a Visualforce page, so here is the code :


    
    
    
    



I know this is not the best approach to go with, and am open for any other solutions or findings.

Dec 28, 2011

Fetching sObject Type From Record Id

"How I can get the sObject Type from Record Id?". In many requirements I do have 15-digit or 18-digit Id and I want to know the sObject to which the Id belongs to. Answer is using Global Describe we can get the sObject type.


Am getting too many emails from folks from Community Forums regarding this, so here is the generic method which will help all.


public class KeyPrefix
{
    // map to hold global describe data
    private static Map<String,Schema.SObjectType> gd;
    
    // map to store objects and their prefixes
    private static Map<String, String> keyPrefixMap;

    // to hold set of all sObject prefixes
    private static Set<String> keyPrefixSet;
    
    private static void init() {
        // get all objects from the org
        gd = Schema.getGlobalDescribe();
        
        // to store objects and their prefixes
        keyPrefixMap = new Map<String, String>{};
        
        //get the object prefix in IDs
        keyPrefixSet = gd.keySet();
        
        // fill up the prefixes map
        for(String sObj : keyPrefixSet)
        {
            Schema.DescribeSObjectResult r =  gd.get(sObj).getDescribe();
            String tempName = r.getName();
            String tempPrefix = r.getKeyPrefix();
            keyPrefixMap.put(tempPrefix, tempName);
        }
    }
    
    public static String GetKeyPrefix(String ObjId)
    {
        init() ;
        String tPrefix = ObjId;
        tPrefix = tPrefix.subString(0,3);
        
        //get the object type now
        String objectType = keyPrefixMap.get(tPrefix);
        return objectType;
    }
}


Now how you can use this? Simply save the class and pass your object Id in method "GetKeyPrefix" like this 


//a0090000002QGKu will be your object Id
System.debug('::::::: '+ KeyPrefix.GetKeyPrefix('a0090000002QGKu') );


And it will return you the object API name.