Monday, 14 April 2014

Common Mistake We Do While Developing.

HI All, 
I am going to address common mistake we do while doing customization in client sandbox.

Mistake-1

We  created one visualforce page(name-testpage) and controller(name-testpageController) for some functionality. To call that page we created one button whose content source is link. We have to provide the link. 
let say link is 
https://c.ap1.visual.force.com/apex/testpage

From link  "https://c.ap1.visual.force.com" this part is known as instance name which differs from org. to org.
However this button will work fine in the sandbox but It wont work if we move changes to production because production must be having different instance name. If we click on button in the production it will show error page does not exists

Remedy for this problem is we will provide link as below.
/apex/testpage   (Don't append instance ).

Mistake-2  

Suppose we created a hyperlink formula field to navigate some visualforce page as below.

HYPERLINK("https://c.ap1.visual.force.com/apex/AccountContactPage1", "AccountPage" ) 

 We will face same error when it is moved to production. To avoid this error we will use formula field as below.
 HYPERLINK("/apex/AccountContactPage1", "AccountPage" )


Mistake-3

We have created one visualforce page where we used <apex:commandLink value="Quick Link" action="/apex/testpage">
Here action means it will navigate testpage. That means current org instance will be appended. However it will work fine in developing org,but in the installed org,it will show same error as above "page does not exists".
As we all know if we create managed package then url will change. Package prefix name will be appended to url. 
Let say instance url of the installed org is  https://c.ap1.visual.force.com/
After installing package instance url will be https://packageprefix.ap1.visual.force.com/

Testpage comes from managed package it will require changed url but command link will append current instance url of the installed org(https://c.ap1.visual.force.com/) ,that is reason why error occurs.

Solutions
1)-Call a pagereference method in the command link. and write this logic in method.
     PageReference samepage = new PageReferenc(/aprx/testpage);
     return  samepage;
2) Use <a href="/apex/testpage"> Quick Link</a> instead of command link.

Mistake-4

 If class and visulforce version is 29 then we need to append prefix name while getting all the fields of an object dynamically otherwise it will show null pointer exception
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
String ObjectName = 'Job__c';
Map <String, Schema.SObjectField> fieldMap = schemaMap.get(ObjectName ).getDescribe().fields.getMap(); 

String ObjectName = 'packageprefix__Job__c';
 

Mistake-5

Sometimes we give hard code link for some functionality. That creates problem so we need to avoid that. Let's take an example we create an object called DiscountObject__c whose key prefix is 0ab.

If we use commandlink like this 

<apex:commandLink value="DiscountObject" action="/0ab/o">

It will navigate to tab page of DiscountObject__c. If we create package and install in different org then key prefix getting changed so its better not to use hardcoded key prefix.

We can get key prefix of an object. Here is one of most you can refer.
http://salesforceworld4u.blogspot.in/2013/12/how-to-get-picklist-value-of-object.html

 
 

No comments: