Tuesday 25 December 2012

JSON to Apex Convesion simpler now with http://json2apex.herokuapp.com

With the REST API being lot used when integrating apps developed on force.com paltform with the mobile applications or integrating force.com with external applications communicating using JSON it becomes vital to know few of open source tool we have to make our task simpler.

When we are in technology consulting world the time becomes crucial in any project we face .

There are couple of tools that i normally use whenever an integration is using REST API and the format of data communication is in the form of JSON .

In this blog i will describe two commonly used applications that makes life simpler when dealing with the JSON data.


This application is very useful to format and Validate the JSON .All you need to do is input the JSON in the text box provided and click on Validate button to Validate the JSON .

JSON Lint is a web based validator and reformatter for JSON, a lightweight data-interchange format.


This was recently developed by salesforce evangelism (SuperFell and PattPatterson) and this is really helpful .The app is on the Heroku paltform and its really helpful of you want to construct an apex class from the JSON you have .

All you need is validated JSON (validate using jsonlint.com) is inputed and just a button click will give you the generated class and also the deserialiser method .

Lets see an example 

Say i have the JSON data as shown below 
{

    "id": "https://login.salesforce.com/id/00D90000000aRkLEAU/00590000000HI32AAG",

    "issued_at": "1355574766264",

    "instance_url": "https://ap1.salesforce.com",

    "signature": "LfOtSilg0GXb8NMO2YwcFvDTjRf8Ml0+jxI3XOozmuw=",

    "access_token": "00D90000000aRkL!ARIAQLLtJXpuyCteMrXEbkbEi6qZcgUhkeaK6_.Yqrxlz8JeOn"

}

Once i input this JSON into the app i get the following result
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class JSON2Apex {

 public String id;
 public String issued_at;
 public String instance_url;
 public String signature;
 public String access_token;

 
 public static JSON2Apex parse(String json) {
  return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
 }
 
 static testMethod void testParse() {
  String json = '{'+
  ''+
  '    \"id\": \"https://login.salesforce.com/id/00D90000000aRkLEAU/00590000000HI32AAG\",'+
  ''+
  '    \"issued_at\": \"1355574766264\",'+
  ''+
  '    \"instance_url\": \"https://ap1.salesforce.com\",'+
  ''+
  '    \"signature\": \"LfOtSilg0GXb8NMO2YwcFvDTjRf8Ml0+jxI3XOozmuw=\",'+
  ''+
  '    \"access_token\": \"00D90000000aRkL!ARIAQLLtJXpuyCteMrXEbkbEi6qZcgUhkeaK6_.Yqrxlz8JeOn\"'+
  ''+
  '}';
  JSON2Apex obj = parse(json);
  System.assert(obj != null);
 }
}
This is really awesome .No more time consumed to draft the apex class Happy Coding!

Sunday 23 December 2012

Handling PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException exception in SFDC Callout

Recently i encountered an exception during making a Callout to the external service .Being an apex developer and unfamiliar with SSL concept much with no luck after googling i tried posting the question in stackexchange Stackexchange link.I am thankful to the Martin Peters for helping me on this .

Through this blog post i would like to document few points i learned on cause of this exception and also i will indicate the solution and resources we have that can help us to get rid of this exception

1)First way to identify this exception is if we try to open the URL we are using to  make a callout to external system in any browser we will encounter the security exception.The below image shows how our browser will behave once encountering such SSL exception.


2)This happens when the external system we make callout from the salesforce does not have valid SSL certificate 

For the JAVA client we have solution on the discussion board .http://boards.developerforce.com/t5/General-Development/PKIX-path-building-failed/td-p/128332

There are two very popular way of implementing authenticated Callouts 

1)one-way SSL/certificate security
2)Two-way SSL 

1)One-Way SSL is easiest implementation :

This blog explains the process for cast iron and i must thank the author of blogger post for such wonderful explanation

So if the external server implements this the problem gets solved straight away.

2)Two-way SSL :
Thanks to the developer.force.com of salesforce that we have an excellent article on how to configure this on salesforce end 

We have a list of SSL certifcates that are accepted by salesforce and verified .Here is the link to the document

Saturday 15 December 2012

Oauth 2.0 Salesforce Using REST Console of Chrome Browser


Earlier in one of my blog post i had demonstrated on how to use Mozilla Poster tool to verify the REST API calls of the salesforce.

Using Chrome REST console has several advantages than poster mozilla .The response can be seen in both JSON and XML and also the concept of oauth 2.0 also can be practically understood .

There are very good articles on 2.0 on the developer.force.com and here is the link Digging deeper into Oauth 2.0

The workbench.developerforce.com has an excellent REST utility which helps in quick verification of Restful Apex services or even standard REST API exposed by the salesforce .One major disadvantage of this is since the oauth happens automatically the conceptual knowledge on how oauth 2.0 works is hidden .

In this blog post we will use the REST Console of the chrome and first get the oauth token from the salesforce instance and then will invoke the REST service from the salesforce .

Step 1-Getting oauth token from salesforce instance 

First step is to set up the remote access settings so that we can obtain the Client secret as well as the clientId

Click On image to View on ful

Step-2-Using the POST call to access the Oauth token from the salesforce 

The payload will be in XML and here is the format of the payload

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

The target URL to obtain token from the salesforce is as follows 



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







Step-3:Making a POST request will yield the JSON with token and here is the snapshot of the issued token from salesforce 












JSON Response Obtained From Server:

{
    "id": "https://login.salesforce.com/id/00D90000000aRkLEAU/00590000000HI32AAG",
    "issued_at": "1355574766264",
    "instance_url": "https://ap1.salesforce.com",
    "signature": "LfOtSilg0GXb8NMO2YwcFvDTjRf8Ml0+jxI3XOozmuw=",
    "access_token": "00D90000000aRkL!ARIAQLLtJXpuyCteMrXEbkbEi6qZcgUhkeaK6_.Yqrxlz8JeOn"
}
The access_token parameter contains the access token can be used in header to access the services

Step 4-The access token is used along with bearer word in the authorisation header to access any rest service.the snapshot shows where the access token needs to be entered in REST console

Click on image to View Full Screen


The response obtained can be changed to XML or JSON using the REST console.
Click on image to View Full Screen





Sunday 2 December 2012

Writing Test Classes For Apex Rest Service

I came across a question in a developer community on how to write Unit Test Classes for the Rest API service for POST HTTP calls

Unit Test Classes for REST API following link is very useful and inspired by this jeff had an article on his blog on how to write the test method for same .

Here is the Jeff Blog Link Test Class for REST API(Good reference for GET Rest Services)


In one of my previous blog post i demonstrated how to use native parsing technique for Rest api for User Defined Type
I wrote the Test class for the same and this post is helpful for all those searching for how to write test classes for apex rest service annotated with POST Call
Here is the Rest Service Class for which i attempted the test class
@RestResource(urlMapping='/DemoUrl/*')
global with sharing class MyRestResourcedemo {

    global class RequestWrapper{
       public  Account acct;
        public Contact[] cons;
    }
  
   global class ResponseWrapper {           
        public String StatusCode;
        public String StatusMessage;
        public Account acct;
        public Contact[] cons;    
    }

@HttpPost
    global static ResponseWrapper doPost(RequestWrapper reqst) {
    
        ResponseWrapper resp = new ResponseWrapper();     
        try{
        insert reqst.acct;
        for(Contact c:reqst.cons){
        c.AccountId = reqst.acct.Id;
        }
        Upsert reqst.cons;
        }
        catch( Exception e ) {
                resp.statusCode = 'Error';
                resp.statusMessage = 'Exception : ' + e.getMessage();
           }
            resp.statusCode = 'Done';
            resp.statusMessage = 'Test success message';
            resp.acct = reqst.acct;
            resp.cons = reqst.cons;

        return resp;
    }
  }

Here is how i wrote my Test class and it ensured my class is covered and i aserted the response
@istest
public class SFA_TestRestPostService {
 
   static testMethod void  testPostRestService(){
   
   Account acc=new Account();
   acc.name='Test';
   acc.AccountNumber='1232332';
   acc.Site='site';
   acc.Website='cloudyworlds.blogspot.in';
   
   List lstcon=new List();

   integer i;
   for(i=0;i<=10;i++){
   Contact c=new Contact();
   c.lastname='Test+i';
   lstcon.add(c);
   }
   
   MyRestResourcedemo.RequestWrapper reqst=new MyRestResourcedemo.RequestWrapper();
   reqst.acct=acc;
   reqst.cons=lstcon;
   
   String JsonMsg=JSON.serialize(reqst);
   
   Test.startTest();
   
   //As Per Best Practice it is important to instantiate the Rest Context 
   
   RestRequest req = new RestRequest(); 
   RestResponse res = new RestResponse();
         
   req.requestURI = '/services/apexrest/DemoUrl';  //Request URL
   req.httpMethod = 'POST';//HTTP Request Type
   req.requestBody = Blob.valueof(JsonMsg);
   RestContext.request = req;
   RestContext.response= res;



   MyRestResourcedemo.ResponseWrapper resp =new  
   MyRestResourcedemo.ResponseWrapper(); 
   resp=MyRestResourcedemo.doPost(reqst); //Call the Method of the Class with Proper       Constructor 
   System.assert(resp.statusMessage.contains('Test success message'));//Assert the response has message as expected 
   System.assert(resp.statusCode.contains('Done'));
   System.assert(resp.acct.Id!=null);//Assert that the Account is inserted and has Id
   Test.stopTest();
   
   }
 }

Some thoughts on best practice can be found on this link of stackexchange

http://salesforce.stackexchange.com/questions/4988/writing-test-classes-for-apex-restservice

Friday 23 November 2012

Sending Document as an attachment in the form of Pdf Using Workflow Rules of force.com platform and Visualforce Template feature


Emailing the pdf on click of a boolean check box or click of a button are frequent requirements for which we often think of using Triggers and using Outbound Emails of apex .

This requirement can be easily accomplished through workflow rules and the Visualforce Email Templates

In this blog POST will walk through on how to approach this

Step 1:
Creation of Email Field This is the first step to create an Email Field so that when we develop workflow rules when for the email alert the Recipient Type is asked we may fill in the email field
Step 2:
Creation of workflowThis is a simple step where based on business criteria draft a workflow rule.Usually rule should be to trigger the email alert only if the boolean flag is checked .
Step 3:Creation of email template The email Template will be a visualforce template and hence if you are familiar with visualforce this must be a straight forward impementation
Below is the sample code that you may customize by replacing with your relevant object name



   
   Please find your  receipt attached with this mail.
   


 


  
    



<!-- Section to insert header-

{!$Label.Header}

Label1 Label 2 Label 3

Image From Notes and Attachment


If have any image to display from documents then you will have to use the following
https://AAA.salesforce.com/servlet/servlet. ImageServer?id=BBB&oid=CCC AAA = your SFDC server, found in the URL of any SFDC link after you log in BBB = the record ID of your publicly available document CCC = your organization ID You can pull from documents.Dont pull from static Resource .It never works .
I answered couple of questions in stackexchange recently and this promoted me to write this blog post so that may help .

http://salesforce.stackexchange.com/questions/4637/is-it-possible-to-have-html-in-a-visual-force-email-template/4639#4639

http://salesforce.stackexchange.com/questions/4641/is-is-possible-to-display-an-image-or-icon-in-a-email-using-a-visualforce-templa/4643#4643

Sunday 4 November 2012

Native Parsing Of JSON input into User Defined Class through Apex Rest Service

I have walked into Apex Guide of SFDC to find if there are code samples for the parsing of the JSON into User defined Class in apex.Unfortunately document mentions that this can be achieved but still there were no code snippets i could find.

This blog post might help for small snippet reference to understand how we can write an apex class and structure the Constructor of the POST annotated method to achieve native parsing automatically.
Here is the Code Snippet of the Class . Note that the Request is a combination of Account and Contacts and hence we may need an inner class .

@RestResource(urlMapping='/DemoUrl/*')
global with sharing class MyRestResourcedemo{

//User defined Class

global class RequestWrapper{
Account acct;
Contact[] cons;
}

//Response Wrapper Class
  
global class ResponseWrapper{           
public String StatusCode;
public String StatusMessage;
public Account acct;
public Contact[] cons;    
}

@HttpPost
global static ResponseWrapper doPost(RequestWrapper reqst){

ResponseWrapper resp = new ResponseWrapper();
     
try{
insert reqst.acct;
for(Contact c:reqst.cons){
c.AccountId = reqst.acct.Id;
}
Upsert reqst.cons;
}
catch( Exception e ){
resp.statusCode = 'Error';
resp.statusMessage = 'Exception : ' + e.getMessage();
}
resp.statusCode = 'Done';
resp.statusMessage = 'Test success message';
resp.acct = reqst.acct;
resp.cons = reqst.cons;
return resp;
}
}
The Request Body is as shown below
{
    "reqst" :
        {
            "acct" : { 
                        "Name" : "Test Account 1",
                       "AccountNumber" : "00000001",
                       "Site" : "Site1",
                       "Website" : "www.site1.com"
                       
                     },
        
            "cons":
                [
                    { "Name": "Test Contact1", "email" : "testcontact1@test.com", "LastName":"TLName2"},
                    { "Name": "Test Contact2", "email" : "testcontact2@test.com", "LastName":"TLName3"},
                    { "Name": "Test Contact3", "email" : "testcontact3@test.com", "LastName" : "TLName"}
                ]
        }
}

The Workbench has REST Utility that simplifies testing.Attached the snapshot.







Saturday 20 October 2012

How to attach an image as an attachment to the parent object using REST API of force.com when image come from client as base64 encoded Text in JSON request

The REST API's offered by the force.com platform has matured lot since previous three versions and this makes it exiting for the integration with other system supporting JSON in their API's
I was reading an article by Sandeep Bhanot(I personally feel he is one of the best in salesforce evangelism) on the platform's ability to deserialise the base 64 encoded image and also decode it .
Here is the link to the article Using Binary Data With REST
Unfortunately my client app(ipad app)was using older version of REST kit that comes along with SDK and they feared upgrading to the newer version
Hence the design was altered to pass the base64 encoded text in the JSON request.Following is the code snippet that we need to decode the binary base 64 encoded image and attach as an attachment to the necessary parent object in sfdc
@RestResource(urlMapping='/Callmanagement/v1/*')
global with sharing class SFA_DoctorsignPoc {
    
@HttpPost
global static String attachdoctorsSign(String encodedSignature){
          
RestRequest req = RestContext.request;
Id callId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Blob pic ;//Blob variable to capture decoded image
if(encodedsignature!=null) {
pic=EncodingUtil.base64Decode(encodedSignature);//Decode the base64 encoded image 
 }
Attachment a = new Attachment (ParentId = callId,
Body = pic,
ContentType = 'image/png',
Name = 'Doctors Signature');
insert a;
return a.Id;
    }
}
Now comes the testing part and good news is that we can use workbench to test this as well
To test this open the workbench REST utility and then you can post the JSON request body
Here is the example request body
{
"encodedSignature":"iVBORw0KGgoAAAANSUhEUgAAAogAAAFACAIAAACweBqpAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAJnNJREFUeF7tncHSA7ltBp0nSary/g+WSlVy9HEjW45WK2mGIAGSH8BO+RSTINDgsIfza9f/9scff/yN/4MABCAAAQhAQITAQ8z8HwQgAAEIQAACIgT+JpIHaUAAAhCAAAQg8I/P2FCAAAQgAAEIQECHAGLW6QWZQAACEIAABLgxswcgAAEIQAACSgS4MSt1g1wgAAEIQOB4Aoj5+C0AAAhAAAIQUCKAmJW6QS4QgAAEIHA8AcR8/BYAAAQgAAEIKBFAzErdIBcIQAACEDieAGI+fgsAAAIQgAAElAggZqVukAsEIAABCBxPADEfvwUAAAEIQAACSgQQs1I3yAUCEIAABI4ngJiP3wIAgAAEIAABJQKIWakb5AIBCEAAAscTQMzHbwEAQAACEJAh8J///h+9/5HJPSwRxByGkkAQgAAEIGAh0Kte+3jL6vpjELN+j8gQAhCAQAUCdr86R2aHhZizd5D8IQABCEgTcFp2YLo0DkNyiNkAiSEQgAAEIDBEYECrryk3CzbDDiWrMgkxq3SCPCAAAQgUI9DU58eA3vLv4/dG0xmPmHV6QSYQgAAE6hCwWDmq2qu1ouIvjoOYFwNnOQhAAAKVCaz08TvHm3XT4UbM6VpGwhCAAARECTStPC/vSp+1EfO8fUJkCEAAAgcRaFr5MWAqjjKXZsQ8dZ8QHAIQgMARBJpWXkOhhpsR85rdwioQgAAEahI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kIQAACEDiNAGI+rePUCwEIQAAC0gQQs3R7SA4CEIAABE4jgJhP6zj1QgACEICANAHELN0ekoMABCAAgdMIIObTOk69EIAABCAgTQAxS7eH5CAAAQhA4DQCiPm0jlMvBCAAAQhIE0DM0u0hOQhAAAIQOI0AYj6t49QLAQhAAALSBBCzdHtIDgIQgAAETiOAmE/rOPVCAAIQgIA0AcQs3R6SgwAEIACB0wgg5tM6Tr0QgAAEICBNADFLt4fkIAABCEDgNAKI+bSOUy8EIAABCEgTQMzS7SE5CEAAAhA4jQBiPq3j1AsBCEAAAtIEELN0e0gOAhCAAAROI4CYT+s49UIAAhCAgDQBxCzdHpKDAAQgAIHTCCDm0zpOvRCAAAQgIE0AMUu3h+QgAAEIQOA0Aoj5tI5TLwQgAAEISBNAzNLtITkIQAACEDiNAGI+rePUCwEIQAAC0gQQs3R7SA4CEIAABE4jgJhP6zj1QgACEICANAHELN0ekoMABCAAgdMI/B9etj40nZT7WQAAAABJRU5ErkJggg=="
}
To convert your image into base64 encode format you can use the http://www.base64-image.de/ .You can upload your image and this gives you the base64 encoded string just attach in your JSON parameter

Please note this is just an alternate solution and not the recommended approach but if there are no options left then not a bad idea to try this for small file load of attachment

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 ...