Friday, 28 September 2012

Tips On Passing Advanced Developer Salesforce Certification(501) multiple Choice Questions

I am glad to share that i cleared Advanced Developer first round .There are already good number of blogs on how to approach this exam.

Following blogs are really good resource and also they give a fair amount of idea on how to approach and how to clear this exam.

1)http://blog.jeffdouglas.com/2009/07/13/i-passed-the-salesforce-com-certified-advanced-developer-exam-so-can-you/
2)http://corycowgill.blogspot.in/2011/05/passing-forcecom-advanced-developer-501.html
3)http://exploresalesforce.blogspot.in/2012/01/how-to-clear-dev-501-exam.html
4)http://www.laceysnr.com/2011/12/five-oh-one-part-one-advanced-developer.html
5)http://limitexception.herod.net/2011/12/14/helping-you-pass-your-501-advanced-developer-exam/

Now my aim is to provide some more points on how to go about it.Please dont refer any dumps or ask for dumps as it is not the purpose of examination .

1)Dont jump into the exam as soon as you clear DEV-401 (developer certification)
2)If you are a developer on the platform and extensively using apex and visualforce page development this is where you are tested whether your skills are proper or not.
3)Pay special attention to the email services and the webservices and also on the Test classes
4)Playing around with all visualforce tags is essential.especially like the apex:componet,apex:composition
5)Know the usage of standard set and list controller
6)Read through apex guide ,visualforce guide (component reference in paticular),migration guide and basic SOQL and best practices of apex

Hope this will be helpful.I am waiting for the opening of registration window for the second round and programming assignment .Will surely share my experience here in this blog.

Saturday, 22 September 2012

New ID.getSObjectType Method in Apex version 26 (Part of winter 13 release)


While i was going through winter 13 release notes of salesforce one of the interesting feature i found was addition of new method ID.getSObjectType.
This will be very helpful in getting the object token without making one more describe call if already in the code we have the List of ID's or ID.
Here is the small snippet i ran in new enhanced developer console(Pretty excited about this new console)
Id accid=[Select Id  from Account Limit 1].ID;
Schema.Sobjecttype inspecttype=accid.getSObjectType();
system.debug('Object Token '+inspecttype);
23:33:30:025 USER_DEBUG [3]|DEBUG|Object Token Account
As seen above this method works great if your sandbox has been updated
Also this method will help in methods where only primitive types can be passed as a parameter like @future where parameter cannot be sObject.

Thursday, 13 September 2012

The New Description on workflows and it makes more sense now !!


Diving deeper into workflows.

The blog below makes life simpler to understand workflow rules after winter 13 releases

http://blogs.developerforce.com/tech-pubs/2012/09/let%E2%80%99s-be-clear-workflow-rule-evaluation-criteria.html

Chaining of Batches in APEX no more pain


Starting a Batch Job from Another Batch Job

You can now start a batch job from another batch job by calling Database.executeBatch from the finish method of the batch class. This allows you to link your batch jobs and create a chain of jobs. Note that the governor limits of batch jobs still apply. This change applies to batch Apex saved using Salesforce.com API version 26.0 and later. Previously, with Apex saved using Salesforce.com API version 25.0 and earlier, you couldn’t call Database.executeBatch from within any batch Apex method. The version used is the version of the running batch class that starts another batch job. If the finish method in the running batch class calls a method in a helper class to start the batch job, the Salesforce.com API version of the helper class doesn’t matter.

Sunday, 9 September 2012

Importance of Virtual Keyword in Apex and when to use Virtual keyword

I have less experience on Java Programming and hence posting this for all those who are familiar with basics of apex but unfamiliar with OOPS concepts like inhertience and polymorphism of Java

Problem description:I knew that the virtual keyword is used to extend a class and thanks to great documentation from salesforce.(http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_example.htm) But my problem is no where in document it is mentioned how to proceed if in my parent class there is a parameterized constructor .

Example:

global virtual class sobjectWrapper{
sobject sobjectDetails;
String RefreshFlag='';
public sobjectWrapper(sobject r){
sobjectDetails=r;
  }
 }

As seen in the above code there is a parametrised constructor.

First i attempted to write the extended the class as shown below

 
global class extutilility extends sobjectWrapper{
sobject sobjectDetails;
String RefreshFlag='';
private string abc;
extutilility(sobject r){
sobjectDetails=r
 }
}

As expected error ...compile time saying " Method does not exist or incorrect signature: [sobjectWrapper].() at line 5 column 1"

Disappointed on my java skills .Had to google little to find what i am i missing.

Here is how it needs to be written

global class extutilility extends sobjectWrapper{
sobject sobjectDetails;
String RefreshFlag='';
private string abc;
extutilility(sobject r){
super(r);
}
}

Use of Super Keyword is what i did not now and here is the exact situation i need badly.

Hope this helps lot of apex developers not familiar with Java completely

Saturday, 8 September 2012

How to generate a Listed JSON from multiple Salesforce Objects(say account and contact) and send data in JSON format to mobile client without nesting Using REST API

Sometimes there is a request for listed JSON .Say we have two objects Accounts and Contacts and we have requirement not to nest the response instead send as a collection with key for list of Accounts as Account and key for Contact as Contact.

Below is the JSON format thats expected output,

{
    "Accounts": [
        {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v25.0/sobjects/Account/001W0000006XDG9IAO"
            },
            "CreatedDate": "2012-08-09T08:29:43.000+0000",
            "LastModifiedDate": "2012-08-09T15:24:42.000+0000",
            "IsDeleted": true,
            "Id": "001W0000006XDG9IAO"
        },
        {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v25.0/sobjects/Account/001W0000006XGEuIAO"
            },
            "CreatedDate": "2012-08-09T15:44:29.000+0000",
            "LastModifiedDate": "2012-08-09T15:50:31.000+0000",
            "IsDeleted": false,
            "Id": "001W0000006XGEuIAO"
        },
        {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v25.0/sobjects/Account/001W0000006QtKyIAK"
            },
            "Phone": "12131",
            "CreatedDate": "2012-08-02T14:46:48.000+0000",
            "LastModifiedDate": "2012-08-09T15:43:20.000+0000",
            "IsDeleted": true,
            "Id": "001W0000006QtKyIAK"
        },
        {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v25.0/sobjects/Account/001W0000006XGI4IAO"
            },
            "CreatedDate": "2012-08-09T15:50:07.000+0000",
            "LastModifiedDate": "2012-08-14T11:33:05.000+0000",
            "FirstName": "Test",
            "IsDeleted": false,
            "Id": "001W0000006XGI4IAO",
            "LastName": "Thomas"
        },
        {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v25.0/sobjects/Account/001W0000006XGIDIA4"
            },
            "CreatedDate": "2012-08-09T15:44:55.000+0000",
            "LastModifiedDate": "2012-08-14T10:15:39.000+0000",
            "FirstName": "shgdshg",
            "IsDeleted": false,
            "Id": "001W0000006XGIDIA4",
            "LastName": "Hello"
        },
        {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v25.0/sobjects/Account/001W0000006XGhwIAG"
            },
            "CreatedDate": "2012-08-09T16:08:14.000+0000",
            "LastModifiedDate": "2012-08-09T16:08:19.000+0000",
            "FirstName": "deleted",
            "IsDeleted": true,
            "Id": "001W0000006XGhwIAG",
            "LastName": "check"
        },

"Contacts": [
        {
            "attributes": {
                "type": "Contact",
                "url": "/services/data/v25.0/sobjects/Contact/003W0000007mNoqIAE"
            },
            "AccountId": "001W0000006XGI4IAO",
            "HCP__c": "001W0000006XGIDIA4",
            "FirstName": "Test",
            "IsDeleted": false,
            "Id": "003W0000007mNoqIAE",
            "LastName": "Thomas"
        },
        {
            "attributes": {
                "type": "Contact",
                "url": "/services/data/v25.0/sobjects/Contact/003W0000007mNp1IAE"
            },
            "AccountId": "001W0000006XGIDIA4",
            "HCP__c": "001W0000006XGEuIAO",
            "FirstName": "shgdshg",
            "IsDeleted": false,
            "Id": "003W0000007mNp1IAE",
            "LastName": "Hello"
        },
        {
            "attributes": {
                "type": "Contact",
                "url": "/services/data/v25.0/sobjects/Contact/003W0000007mNpGIAU"
            },
            "Phone": "3213",
            "AccountId": "001W0000006XGEuIAO",
            "HCP__c": "001W0000006XGIDIA4",
            "IsDeleted": false,
            "Id": "003W0000007mNpGIAU",
            "LastName": "ueiru"
        },
        {
            "attributes": {
                "type": "Contact",
                "url": "/services/data/v25.0/sobjects/Contact/003W0000007wAkwIAE"
            },
            "Phone": "206-999-1111",
            "AccountId": "001W0000006XJ3fIAG",
            "Email": "mwells@ubermind.com",
            "HCP__c": "001W0000006XGIDIA4",
            "FirstName": "Mark",
            "IsDeleted": false,
            "Id": "003W0000007wAkwIAE",
            "LastName": "Wells"
        }
]}

For this we will have to use customized wrapping ,

Following is the source code that will automatically handle the generation of JSON in the expected format,

global class SFA_AccountContactListedResponse{
 //Wrapper class to warp the various  List as Super wrapper
 global class supersobjectWrapper{
List Accounts=new List();//A list to hold the Accounts
List Contacts=new List();//A list to hold the Contacts  
}
//This method will be called as the http get request
public static supersobjectWrapper makeResponseString(){  
List  lstacc=new List();
List lstcontacts=new List();
lstacc=[Select Id,CreatedDate,LastModifiedDate,Isdeleted from Acccount ];
lstcontacts=[Select id,CreatedDate,LastModifiedDate,Isdeleted from Contact];
supersobjectWrapper superWrap=new supersobjectWrapper();//Instantiating thesuperclass
superWrap.Contacts= lstcontacts ;
superWrap.Accounts= lstacc;
return superWrap;
 }
}

The above class will be called as REST API using GET HTTP call,

@RestResource(urlMapping='/GetAcc/*')
global with sharing class SFA_ListedJsonGenerator{ 
@HttpGet
global static SFA_AccountGroupSyncManagerRevised.supersobjectWrapper returnJsonpacket(){ 
RestRequest req = RestContext.request;
SFA_AccountGroupSyncManagerRevised.supersobjectWrapper result;  
result=SFA_AccountContactListedResponse.supersobjectWrapper;
return result;
    }
}

Monday, 3 September 2012

Visualforce changes to display date field in proper format


Today when my friend ran into trouble while displaying date field on visualforce with proper format i had no answers . The date format was not proper as expected . Following snippet helped me lot .Posting so that may help others

apex:outputText value=”{0,date,MM’/'dd’/'yyyy}”>


Few Intresting Tips On Making a Field Mandatory On Visualforce Page


Inspecting the CSS of the salesforce and playing around a bit we can easily make a field look like a required field with the help of below snippet





The validation can be easily handled at the back end and a small code that will be helping is below

if(is error){
ApexPages.addmessage(new ApexPages.Message(ApexPages.Severity.Error, 'Error Message.........'));
}
 tag has to be added in the page to display the error to the user.

Sunday, 2 September 2012

Handling Exceptions In REST API wrappers in salesforce and setting proper HTTP error in header of HTTP response sent from Salesforce

To set the proper error code in the response packet returned from salesforce there is default HTTP error code table

The documentation of valid http error codes supported is in the http response is accessed on clicking below Documentation on HTTP error codes

To handle this in code here is a below simple example that demonstrates how to set the HTTP error codes in salesforce

@RestResource(urlMapping='/Account/*')
global with sharing class accountrest {
@HttpGet
global static Account getMerchandiseById() {
RestRequest req = RestContext.request;
RestResponse res=RestContext.response;
Account result;
String accId = req.requestURI.substring(
req.requestURI.lastIndexOf('/')+1);
 try{
  result =[SELECT Name,AccountNumber,NumberofLocations__c FROM Account WHERE Id = :accId];
}
catch(exception e){
System.debug(e.getMessage());
res.statusCode=400;//clear that error was due to account ID missing and hence BAD request
}
return result;
}

Saturday, 1 September 2012

cloudy: Using POSTER mozilla tool to get oauth token and access the REST API of salesforce

Using POSTER mozilla tool to get oauth token and verifying response from REST API salesforce Please follow the following steps:


Use this first as a request URL to get access token .Please use test.salesforce.com for sandbox

2)To obtain access token you must Use POST http call:
In the payload use

grant_type=password&client_id=<your_client_id>&client_secret=<your_client_secret>&username=<your_username>&password=<your_password>

where client id,client secret you will get from your remote access settings and please append security token if you are making from unautorized IP range .Please use appropriate User Name and Password

3)Once you POST to the service you will get acess token .Please save that for future requests

4)Next in the header add following parameter and its value as 
Name:Authorization
Value:Bearer +oauthtoken obtained (Bearer space and your oauth_token)

5)Now once you add header in request URL add your REST service URL in the request URL of Poster tool(eg:https://ap1.salesforce.com/services/apexrest/CaseManagement/v1/50090000004TBNU) 

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...