Skip to main content

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

 
 

Comments

Popular posts from this blog

How to Create a Tooltip in Lightning Datatable ?

Imagine you have a datatable displaying a list of Contact records , and one of the columns shows the Account Name . The Account Name is a hyperlink that allows users to navigate to the Account record page. But what if users want to take a quick glance at some key Account fields —like Phone or Address—without navigating to the Account record? In Salesforce Classic, this was achieved using the Mini Page Layout feature from standard page. However, in Lightning Experience, we can implement a similar feature by adding a tooltip to the data table. Solution Overview: We’ll create a Lightning Web Component (LWC) that: Displays a data table with a clickable Account Name . Provides a tooltip that shows the Account's Phone and Address fields when users hover over the Account Name. Implementation Steps: 1. Data Preparation We need to retrieve the following fields for each Contact and its associated Account: Contact Fields : Name, Phone, Email Account Fields : Name, Phone, Billing Addre...

Lifecycle hooks in LWC

There are 3 phase of LWC component  1. Mounting  A. constructor, B. connnectedCallback C. render D. renderedCallback 2. UnMounting  A. disconnectedcallback 3. Error  A.errorcallback Note - render is not lifecycle hook, it is protected method of Lightning element class. Mounting Phase LWC Creation and Render Life cycle Constructor Method ·        This method called when component is instantiated and It flows from parent to child component. ·        Need to call Super() inside constructor method ·        Can’t access any component properties or child component because it’s not ready yet. ·        Host element can be accessed through “this. template” inside constructor method. ·        Don’t add any attributes to host inside constructor C   constructor (){          super (); //...

How to Create/Delete file attachments(Content Document) through Apex ?

 There are 3 standard salesforce objects to store file attachments. Content Document, ContentDocumentVersion, ContentDocumentLink.  Here is the article to talk about these objects and relationship.  https://www.forcetalks.com/blog/contentdocument-and-contentversion-in-salesforce-an-overview/ ContentDocumentVersion ContentDocumentLink This post is all about how to create/delete content document though Apex. Here is code snippet // Insert Content Version record ContentVersion contentVersionRec = new ContentVersion(Title='filename',PathOnClient ='FileName.pdf',VersionData = bodyBlob,origin = 'H'); INSERT contentVersionRec; // this will insert one record in ContentDocument and ContentVersion , ContentDocument  is parent and  ContentVersion is child record // get contentdocument id contentVersionRec = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionRec .Id LIMIT 1]; // Create Content Document Link record- This will attach ...