Tuesday 16 February 2016

Brain Bout for Salesforce Sandbox

What is a sandbox?
Sandbox is a term used for replica copy isolated from the production environment. It is used for development, testing , backup and training purpose for an organisation. These environment are near to exact copy of the schema and data model of the production instance.

Changes done to each of the environment(sandbox or prod) don't affect each other's date state/schema state. Sandbox  Login  URL :  https://test.salesforce.com

NOTE: Sandboxes can only be created from Production Instance and Information about various sandbox is listed in production.

To create a Sandbox:

  1. Goto Setup, click Sandboxes or Data Management |Sandboxes.
  2. Click New Sandbox.
  3. Enter a name and description for the sandbox.
  4. Select the type of sandbox.
  5. Select the data to include in your Partial Copy or Full sandbox.
  6. Click Create.
Depending upon type of sandbox chosen in above steps, Data and various configuration will be copied to the metadata while creating a sandbox. Sometimes the users are not with Full copy sandbox(Dont' worry read along to know about Types of Sandbox and their features) which enables to copy production data along with schema so in that case we can use DataLoader tool or Dataloader.io to import desired data from production into newly created sandbox.

  1. Developer Sandbox : It is the most basic type of sandbox available to most of the customers.These environments include a copy of your production organization’s configuration (metadata) only. This type of sandbox is mostly suitable for Development purpose.
  2. Developer Pro Sandbox : It is a superset of Developer Sandbox i.e Developer pro sandbox consists of all the features associated with Developer sandbox plus it has larger Data Storage which is very helpful in maintaining the unit test record for quality assurance tasks. No production data is copied for this type of sandbox.
  3. Partial Copy Sandbox : It is capable of including a copy of your production organization’s configuration (metadata), and a subset of your production data as defined by a sandbox template. This environment is mainly used for quality assurance tasks, acceptance testing , integration testing etc.
  4. Full Copy Sandbox : It is the most advanced type of sandbox which are mainly intended for UAT, backups, training purpose, performance testing, load testing, and staging. It can be assumed as an exact copy of production environment. It has long refresh time intervals which makes it difficult to use Full sandboxes for development.
Tasks performed by Salesforce while creating or refreshing a Sandbox: 
  • Usernames are modified by appending them with sandbox name to each username.
  • Email fields for each user is also changed in a format like salesforcel1support3=abc.com@example.com

Thursday 11 February 2016

Salesforce Dynamic Visualforce Components

Use Salesforce Dynamic Visualforce Components and Custom Label for predefined String(helpful for displaying Apex Messages etc)

Visualforce is mainly intended for create static pages by using Different namespace tag and dynamically populating the values based on controller binded variables but sometimes Developers need to customize the Pages in such a way to reduce maintainance Development effort and the changes could be carried out in few point and clicks. To adapt this strategy, Salesforce provided -"Dynamic Visualforce Components", Under this approach VF components are dynamically populated in APEX class and then rendered onto the VF page.

Custom Label usage: Developers can use Custom Labels in Apex by using following expressions - System.Label.labelName

VF Page :
1:  <apex:page standardController="Contact" extensions="DynCompExample">  
2:    <apex:dynamicComponent componentValue="{!headerWithDueDateCheck}"/>  
3:    <apex:dynamicComponent componentValue="{!ErrorLabelString}"/>  
4:  </apex:page>  

APEX Class:
1:  public class DynCompExample {  
2:    public DynCompExample(ApexPages.StandardController con) { }  
3:    public Component.Apex.SectionHeader getHeaderWithDueDateCheck() {  
4:      date dueDate = date.newInstance(2016, 2, 8);  
5:      boolean overdue = date.today().daysBetween(dueDate) < 0;  
6:      Component.Apex.SectionHeader sectionHeader = new Component.Apex.SectionHeader();  
7:      if (overdue) {  
8:        sectionHeader.title = 'This Form Was Due On ' + dueDate.format() + '!';  
9:        return sectionHeader;  
10:      } else {  
11:        sectionHeader.title = 'Form Submission';  
12:        return sectionHeader;  
13:      }  
14:    }  
15:       // This method return the String value for the Error Label id   
16:    public Component.Apex.OutputText getErrorLabelString(String labelName){   
17:            Component.Apex.OutputText outputError = new Component.Apex.OutputText();   
18:            outputError.expressions.value = '{!$Label.' + labelName + '}';   
19:            return outputError;   
20:       }   
21:  }  

Note from Salesforce : Dynamic Visualforce components are not intended to be the primary way to create new Visualforce pages in your organization. Existing Visualforce pages shouldn’t be rewritten in a dynamic manner and, for most use cases, standard Visualforce components are acceptable and preferred. You should only use dynamic Visualforce components when the page must adapt itself to user state or actions in ways that can’t be elegantly coded into static markup.

Documentation  Link : https://help.salesforce.com/HTViewHelpDoc?id=cl_about.htm&language=en_US

Wednesday 10 February 2016

Using NewLine in APEX String

String is an awesome DataType provided by Language designers to store any Text Literals(alphabets, numbers, special chars etc) but sometimes Developers need to display Newline Character in the APEX String which can be used on VisualForce Page.

Trick : This can be easily done adding \n for NewLine Character in Apex String and then each \n will be replaced by <br/> in VF page with help of SUBSTITUTE(JSENCODE(Variable), '\\n', '<br/>').

VF Page :
1:  <apex:page controller="Returns">   
2:    <apex:outputLabel value="{!SUBSTITUTE(JSENCODE(choosenText), '\\n', '<br/>')}" escape="false"/ >   
3:   </apex:page>  

Apex Class :
1:  public class Returns{  
2:  public String choosenText{get;set;}  
3:  public Returns(){  
4:  choosenText = 'Hi Salesforce' + '\n' + ' This is a Salesforce Techie Blog.' + '\n' + 'Please share your Feedback';  
5:  }  
6:  }  

Output :
 

Hope this trick is Helpful!!!