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

Style in LWC

 Following are the ways we can apply in CSS in LWC. 1. Inline CCS Inline CSS is not recommended approaches, it is take highest priority among all CSS. style="color:green;font-size:10px;" is inline CSS added to div < template >     < lightning-card title = "Inline CSS" >         < div >             < div style = "color:green;font-size:10px;" > This is inline Style div </ div >         </ div >     </ lightning-card > </ template >  2. External CSS style can be applied to an elements such as h1, p,div span etc. It can applied to class using "." notation. for example .user{} It can also be applied to pseudo class.  for example .user:hover{} Id locator is not being used in LWC to apply style To apply external css, need to create separate CSS file, file name should be exactly matched with component name. for example - If component name is ...

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

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 (); //...