Aug 13, 2014

Not sure why you attend Dreamforce?

Dreamforce is on it's way, and we all are excited about it (me for sure). If you are still not sure you should attend Dreamforce then below is some awesome stuff which you'll be missing.

-> Best part is the DEV ZONE for developers like me, a lot of fun stuff there like super awesome breakout sessions, theaters and FREE books :-)


Along with this you will find these people walking around you and you can say HI! to them, April, Patt Peterson, Raja Rao, Kavindra Patel, Sandeep Bhanot (list is very very long, please forgive me if I've not written all the names as for that I'll need another blog post :-) )


-> Besides Dev Zone, most important part is the networking. You can meet people who are related to different area. Say if you are running your own business, you will get a change to connect with lot of ISVs or small/big company owners who can help you with your business. If you are emerging developer, then you can connect with Salesforce Developer Evangelists, Salesforce Developer Relationship Managers etc. Confused how to connect with them? Twitter is the best way to follow them and connect with them.


-> Some other benefits are you'll get to know about the latest trends and how world is growing with Salesforce. Say what's new with Salesforce1, what's new on mobile side and stuff. Superb keynote sessions, and our very own Marc Benioff's session and Q&A. Hands on training and code consulting session, again list is very long.


To know more visit this link http://bit.ly/df14infblog


-> I'll also be speaking and my session is "FYFOF - Find Your Feet On Force.com", so if you are a beginner or want to learn how you can grow with Salesforce then I hope to see you in my session.


Don't worry about the long flight to SFO (if you are going from India) and expense as it's worth it. So be ready with your visa and book your tickets now before you are too late (Dreamforce 14 is between 13-16 Oct 2014)


Hope to see most of you at Dreamforce.

Jun 30, 2014

Summer 14 Release - Developer Must Know These

So Summer 14 release is almost there and in few more days it will be in our organizations. So are we ready to us the new features/changes?



Let's go through some points which a developer must know, to write Apex/VFP in better way. 

List is as follows :

1) Attach upto 25 MB of files now with objects, earlier it was 5 MB. But, attachment limits in Salesforce Knowledge remain unchanged. So go on and use large data files.

2) Limits for all Apex describe calls have been removed for all API versions. Describe calls include describes for sObjects, fields, field sets, child relationships, picklists, and record types. In other words say no to, ONLY? 100 fields or fieldsets or objects. Yes now we are free :-)



Will these be now needed?

- getLimitChildRelationshipsDescribes()
- getLimitFieldsDescribes()
- getLimitFieldSetsDescribes()
- getLimitPicklistDescribes()
- getLimitRecordTypesDescribes()

3) The Limits methods for script statements have been removed but are available and deprecated in API version 30.0 and earlier. Because the script statement limit is no longer enforced in any API version since Winter ’14, the associated Limits methods are no longer needed. Now no need of getScriptStatements() and getLimitScriptStatements()

4) Now you can create price book entries for standard and custom price books in Apex tests. Previously we were not able to create price book entries and for that we've to use @isTest(seeAllData = true) annotation. So now we can create custom pricebook along with the pricebook entries in test classes itself. Now we can

- Query for the ID of the standard price book in organization with the Test.getStandardPricebookId() method.
- Create test price book entries with standard prices by using the standard price book ID that’s returned by Test.getStandardPricebookId().
- Create test custom price books, which enables you to add price book entries with custom prices.

5) Run future methods with higher limits, unbelievable isn't it? But currently it's in pilot. By this we can avoid reaching governor limits and we can double or triple the capacity of resources like for heap size we can write this @future(limits='2xHeap'), for SOQL @future(limits='2xSOQL') and so on. Fascinating isn't it, eagerly waiting for this to be implemented completely.



6) Chatter in apex. Lot of stuff in this, and difficult to summarize it here would recommend to read release notes.

7) API request in developer edition was 5,000 and now it's raised to 15,000. So now we can do some real time testing along with development.

Lot of stuff to be improved in current code and am on it, are you?

May 11, 2014

Google Drive Authentication In Salesforce - Easy Steps (Authentication Part 2)

Now where comes part 2 of authentication. This time it's with Google Drive.

In this blog Authentication with Google is explained so developers can get started.

Step 1 : Create  account on google (hope you already have), then go to developer console to create a project. Now click on project which is newly created then click on APIs and auth > APIs and make Drive API "on".

Step 2 : Now "Create New Client ID " which will look something like this :


Now we will use this info in salesforce to authenticate.

Step 3 : Create this apex class in Salesforce

public class GoogleDriveController
{
    //Fetched from URL
    private String code ;
    private string key = '134427681112-ld4vp2l1jut3aj2fktip776081nhn8l3.apps.googleusercontent.com' ;
    private string secret = 'hdHNk4GjNtkR4nNL1SqCfRk_' ;
    private string redirect_uri = 'https://c.ap1.visual.force.com/apex/GoogleDrivePage' ;
    
    public GoogleDriveController()
    {
        code = ApexPages.currentPage().getParameters().get('code') ;
        //Get the access token once we have code
        if(code != '' && code != null)
        {
            AccessToken() ;
        }
    }
    
    public PageReference DriveAuth()
    {
        //Authenticating
        PageReference pg = new PageReference(GoogleDriveAuthUri (key , redirect_uri)) ;
        return pg ;
    }
    
    public String GoogleDriveAuthUri(String Clientkey,String redirect_uri)
    {
        String key = EncodingUtil.urlEncode(Clientkey,'UTF-8');
        String uri = EncodingUtil.urlEncode(redirect_uri,'UTF-8');
        String authuri = '';
        authuri = 'https://accounts.google.com/o/oauth2/auth?'+
        'client_id='+key+
        '&response_type=code'+
        '&scope=https://www.googleapis.com/auth/drive'+
        '&redirect_uri='+uri+
        '&state=security_token%3D138r5719ru3e1%26url%3Dhttps://oa2cb.example.com/myHome&'+
        '&login_hint=jsmith@example.com&'+
        'access_type=offline';
        return authuri;
    }
    
    
    public void AccessToken()
    {
        //Getting access token from google
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint('https://accounts.google.com/o/oauth2/token');
        req.setHeader('content-type', 'application/x-www-form-urlencoded');
        String messageBody = 'code='+code+'&client_id='+key+'&client_secret='+secret+'&redirect_uri='+redirect_uri+'&grant_type=authorization_code';
        req.setHeader('Content-length', String.valueOf(messageBody.length()));
        req.setBody(messageBody);
        req.setTimeout(60*1000);

        Http h = new Http();
        String resp;
        HttpResponse res = h.send(req);
        resp = res.getBody();
        
        System.debug(' You can parse the response to get the access token ::: ' + resp);
   }
}


Step 4 : Create this visualforce page (GoogleDrivePage) in Salesforce



    
        
    




Step 5 : Replace the code :

You can replace these three variables according to your settings (created in step 2)

private string key = '134427681112-ld4vp2l1jut3aj2fktip776081nhn8l3.apps.googleusercontent.com' ;
private string secret = 'hdHNk4GjNtkR4nNL1SqCfRk_' ;
private string redirect_uri = 'https://c.ap1.visual.force.com/apex/GoogleDrivePage' ;

Step 6 : Don't forget to create remote site setting :


Step 7 : All set to go, now hit the page "https:// ..... /apex/GoogleDrivePage", make sure your debug is on. Once authenticated with google debug will print the access token.


Now you can use this access token for further requests.

Please note, code is not beautified as this is just to explain how you can authenticate google with salesforce. A lot more creativity can be applied here.


Happy Coding!!

May 9, 2014

Dropbox Authentication In Salesforce - Easy Setup (Authentication Part 1)

From log time managing data is a big deal, and a lot are concerned with it. Multiple options are available to handle this, out of them Dropbox, Box.com, Amazon are the main ones.

In this blog Authentication with Dropbox is explained so developers can get started.

Step 1 : Create an account on Dropbox, then go to this link and create an app. It will create "App Key" and "App Secret" which we will be using in Salesforce. Leave the OAuth2 section blank for now.


Step 2 : Go to salesforce and create this apex class (DropboxController) :

public class DropboxController
{
    //Fetched from URL
    String code ;
    
    public DropboxController()
    {
        code = ApexPages.currentPage().getParameters().get('code') ;
        //Get the access token once we have code
        if(code != '' && code != null)
        {
            AccessToken() ;
        }
    }
    
    public PageReference DropAuth()
    {
        //Authenticating
        PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=vaabb5qz4jv28t5&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&state=Mytesting') ;
        return pg ;
    }
    
    public void AccessToken()
    {
        //Getting access token from dropbox
        String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&code='+code+'&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage'; 
        HttpRequest req = new HttpRequest();
        req.setEndpoint(tokenuri);
        req.setMethod('POST');
        req.setTimeout(60*1000);
          
        Blob headerValue = Blob.valueOf('vaabb5qz4jv28t5' + ':' + 'dpmmll522bep6pt');
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        Http h = new Http();
        String resp;
        HttpResponse res = h.send(req);
        resp = res.getBody();
        
        System.debug(' You can parse the response to get the access token ::: ' + resp);
   }
}


Step 3 : Now create visualforce page (DropboxPage) :



    
        
    




Step 4 : Replace the code with your values

1 . As you can see we have this in code :

PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=vaabb5qz4jv28t5&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&state=Mytesting') ;


You have to replace "client_id" with your "App Key" (redirect_uri is the complete page URL which we've just created). Now as visualforce page is created you can fill the OAuth2 section as shown in the screenshot above in dropbox.

2. Replace "dpmmll522bep6pt" in this line
Blob headerValue = Blob.valueOf('vaabb5qz4jv28t5' + ':' + 'dpmmll522bep6pt');
with you "App Secret"

Step 5 : Don't forget to set the remote site settings for dropbox



Now all set to go. Open the page "https:// ..... /apex/DropboxPage" and hit "Dropbox Authentication". In the debug you will get the access token which you can further use to hit Dropbox APIs.

Please note, code is not beautified as this is just to explain how you can authenticate dropbox with salesforce. A lot more creativity can be applied here.

From here everything is set and you are ready to hit the dropbox API and fetch the data or store the data. Complete documentation is here.

Happy Coding!!

May 7, 2014

Salesforce1 Developer Week - Jaipur Meetup

Salesforce organized a global event where around 70 Salesforce Developer Groups across the world talked about Salesforce1. We are proud to be part of the 1.5 Million developers in the Salesforce Developer Community and celebrated by taking part in Salesforce1 Developer Week on April 27th.

Special attraction of the event was Raja Rao DV (Developer Advocate, Salesforce.com) presented live in the group that what can be built using Salesforce1. Hope now every attendee learned what is Salesforce1 and how to get started.


Followed by Sandeep Singhal (Leader of Jaipur Salesforce Platform Student User Group) explained a little more introduction of Salesforce1 within Salesforce.


Now all were hungry, so it was time for lunch.


All set to go, here comes Amit Jain (Salesforce and Mobile Developer). Amit, presented on how we can develop an app by only points and clicks. It was making everything permanent in mind, what we've learned in last two sessions.


It was time to learn something advance, and who else is best to take this off. Gaurav Kheterpal (Mobile Guru, Salesforce Expert, Speaker, Author (space is not enough)) takes the show away by explaining mobilizing your apps with Salesforce1.




Workbooks were distributed to all, to get started. If you were not one of the attendee then here is the link to download it.


In the end the most awaited part of the event "The Quiz". Where super cool T-Shirts were distributed to all winners.



Over all it was a great success and response from all was very good. If you want to join us in upcoming meetups please join us here.



For more pictures and details of the event visit here.

Jun 12, 2013

Cow and Bull In Salesforce - Let's Brainstorm

Hope may of you are aware of the game Cow & Bull, but those who are not here are the rules

1) Computer will generate a 4 digit number which you need to guess in less than 10 chances
2) This number will not start from 0
3) All digits of the number will be unique (no digit will repeat)

For example:

1234 - is correct
0234 - is wrong
3445 - is wrong

Now user will input a 4 digit number which doesn't starts with 0 and all digits are unique. Computer will then compare with it's generated number and tell you the count of cows and bulls.

What is Cow and Bull

1) Cow: When digits of your number matches digits of computer's generated number on same index

For example: Computer generated > 4580

Your guess > 4619
Count of cows will be one as only one digit matches on same index.

If your guess is > 4689
Then count of cows will be 2 as "4" and "8" both matches at same index

2) Bull: When digit of your number matches digits of computer's generated number but not on same index

For example: Computer generated > 4580

Your guess > 6419
Count of bulls will be one as only one digit ("4") matches (but on same index).

If your guess is > 4689
Then count of bulls will be 2 as "4" and "8" both matches (but on same index)

So if you guessed 4851, then there is ONE cow ("4") and TWO bulls ("8" and "5")



Now it's time to use the brain, here is the site link: http://bmprojects-developer-edition.ap1.force.com/CB_CowAndBull


VFP:


<apex:page controller="CB_CowAndBullController" showHeader="false" sidebar="false">
    <apex:form id="FRM">
        <apex:pageBlock id="PB" title="Cow And Bull">
            
            <apex:pageMessage severity="INFO" escape="false">
                1) Enter 4 digit number which have all digits unique and is not starting from 0 <br/><br/>
                2) Cows: Digits from your number matches computer's number at same index <br/>
                e.g: You Enter -> 1234 and Computer Number -> 1960 <br/>
                1 matches on same index so it will be counted as cow <br/><br/>
                3) Bulls: Digits from your number matches computer's number but not on same index <br/>
                e.g: You Enter -> 1234 and Computer Number -> 9120 <br/>
                1 and 2 matches but not on same index so it will be counted as bull
            </apex:pageMessage>
            <apex:pageMessages id="PM"/>
            
            <apex:pageBlockButtons rendered="{!IF(showButton , true , false)}">
                <apex:commandButton value="Check C&B" action="{!CheckCandB}"/>
            </apex:pageBlockButtons>
            
            <!-- <apex:outputText value="Computer Generated Number : {!CompNumber}"/> -->
            
            <apex:pageBlockSection id="PBS1">
                <apex:pageBlockSectionItem id="PBSI1">
                    <apex:outputLabel value="Please Enter Your Number:"/>
                    <apex:inputText size="4" value="{!userEnteredNUmber}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            <apex:pageBlockTable rendered="{!IF(toDisplayWrapperLst.size > 0 , true, false)}" value="{!toDisplayWrapperLst}" var="wrap">
                <apex:column headerValue="Your Input" value="{!wrap.userInput}"/>
                <apex:column headerValue="Cows" value="{!wrap.cow}"/>
                <apex:column headerValue="Bulls" value="{!wrap.bull}"/>
            </apex:pageBlockTable>
        
        </apex:pageBlock>
    </apex:form>
</apex:page>


Apex Code:


public class CB_CowAndBullController
{
    public Integer CompNumber {get; set;}
    public Integer userEnteredNUmber {get; set;}
    //To maintain the user inputs
    public List<userInputResults> toDisplayWrapperLst {get; set;}
    //Flag to show the button which compare the user input with computer's generated number
    public boolean showButton {get; set;}
    
    public CB_CowAndBullController()
    {
        //Number entered by user
        userEnteredNUmber = 0 ;
        
        showButton = true ;
        
        toDisplayWrapperLst = new List<userInputResults>() ;
        
        //Generating 4 digit number which doesn't start with 0 and no number is repeated
        boolean flag = false ;
        while(!flag)
        {
            Integer tempVar = Integer.valueOf(Math.Random() * 10000) ;
            if(checkNumber(tempVar))
            {
                flag = true ;
                CompNumber = tempVar ;
            }
        }
    }
    
    private Boolean checkNumber(Integer num)
    {
        //Pattern for 4 digit number which doesn't start with 0 and no number is repeated
        Pattern nonZeroPattern = Pattern.compile('([1-9])(?!.*\\1)([0-9])(?!.*\\2)([0-9])(?!.*\\3)([0-9])(?!.*\\4)');
        Matcher nonZeroMatcher = nonZeroPattern.matcher(''+num);
        if(nonZeroMatcher.matches())
             return true;
        else
            return false ;
    }
    
    public PageReference CheckCandB()
    {
        if(checknumber(userEnteredNUmber))
        {
            //Logic to compare user input and computer's generated number
            Integer cow = 0 ;
            Integer bull = 0 ;
            String UEN = string.valueOf(userEnteredNUmber) ;
            String CGN = string.valueOf(CompNumber) ;
            
            for(Integer i = 0 ; i < UEN.length() ; i++)
            {   
                for(Integer j = 0 ; j < CGN.length() ; j++)
                {
                    if(UEN.subString(i , i+1) == CGN.subString(j , j+1))
                    {
                        if(i == j)
                            cow = cow + 1 ;
                        else
                            bull = bull + 1 ;
                    }
                }
            }
            toDisplayWrapperLst.add(new userInputResults(cow, bull, userEnteredNUmber)) ;

            if(cow == 4)
            {
                showButton = false ;
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Congratulations! You guessed it right in ' + toDisplayWrapperLst.size() + ' chances.'));
            }
            else
            {
                if(toDisplayWrapperLst.size() > 9)
                {
                    showButton = false ;
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'You failed to guess the number in 10 chances. Better luck next time.'));
                }
            }
        }
        else
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please enter a 4 digit number which does not start with 0 and no number is repeated' ));
        }
        return null ;
    }
    
    //Wrapper to maintain number of cows, bulls and user input
    public class userInputResults
    {
        public Integer cow {get; set;}
        public Integer bull {get; set;}
        public Integer userInput {get; set;}
        
        public userInputResults(Integer c, Integer b, Integer ui)
        {
            cow = c ;
            bull = b;
            userInput = ui ;
        }
    }
}


Would love to hear the feedback.

Apr 30, 2013

How Can I Become A MVP (Force.com)

Recently my MVP title is renewed (Extra! Announcing our newest and renewed Force.com MVPs) and this question bothered many from time to time "How can I become a MVP"? 

Don't focus on how to become a MVP, focus only on the motive behind the program. It is stated that "Force.com MVP program recognizes outstanding contributors and technological leaders in the Force.com cloud platform ecosystems. Force.com MVPs are being called out for willingly sharing their expertise with others, demonstrating stewardship of the community in which they play an integral part, advancing the community body of knowledge and strengthening the developer network." 

Now there are multiple ways to do this, let's talk about some of them: 

1) Contribution via discussion boards, which is the heart of community. We've multiple discussion boards where you can share your knowledge with other community members.


2) Evangelism of the technology through independent publication such as blogs/whitepapers/FB Page 

3) Contribution to open sources. If you've ever thought about sharing some code samples or some big projects so don't let it be restricted to only your personal blogs. Make them live here:


4) Get Social and stay connected with other peers on social sites like

  • Twitter : Follow official accounts @forcedotcom @salesforce and use #askforce if you need any help or you want to help the community
  • Facebook : Like the official page and stay connected with the latest news and events
  • LinkedIn etc.

5) Participate as much as you can via attending live webinars (you can get the information from social sites or here), online events (where you get chance to win some cool stuff), online challenges like this 

6) Participate in local developer user group meetings. You can get the list of all developer user groups here.

7) Participate in big events like Dreamforce, Cloudstock etc.

List never ends and it's benefits too, like by doing all this

  • Your knowledge will be increased.
  • Your networking will be strong
  • Will be acknowledged globally
  • Significant increase in offers from companies
  • Domain will not be restricted any more
  • After actively participating in events your wardrobe will be full of some cool stuff like Jackets, T-Shirts, Caps, Bags, Trophies, Books, Hoodies


Above benefits are for sure, and if you are entitled as MVP then there are some additional benefits to above:

  • You'll get sponsored trips to SF for events like MVP Summit
  • You'll get free passes to Dreamforce
  • Highlighted community profile, (here is mine)
  • Early access to feature previews and releases, with direct feedback to the PMs on these products
  • Access to chatter groups where all MVPs jam together



I don't know where to stop...so now you have the links and I hope you know what to do. GOOD LUCK!

Make our community rock!!