Pages

Salesforce.com testMethod / Apex Unit Testing Limitations

Following are my top three Salesforce.com test platform limitations.

1. Cannot remove/revalidate page messages in same test Method :
Handling the error messages and exceptions and then displaying users with the user friendly error message is one of the important aspect of your visualforce page. One of the basic flow you want to test is the behaviour of your visualforce page to display the error messages and on correcting the inputs users are allowed to proceed to next screen or step. This scenario cannot be tested in a single test method. Salesforce.com has this limitation as in a test method when you add error messages in the page you won't be able to remove/revalidate the messages even after updating the input values.

2. Email Templates in your organisation are visible to test methods even after (@seeAllData=false) :
Salesforce cannot isolate/hide Email Templates if present in your organisation. Consider you writing a test scenario where user will be presented with some predefined email templates based on some user field. As best practice even though you write your test methods in isolation using @SeeAllData=false You will see the existing Email Templates being visible in your test method.

3. You cannot created Email Template And Document Folders in a Test method :
You cannot create Document/Email Template Folders in a test method. You have to relay on the Salesforce Environment to make sure you create at least one Folder manually for your test methods to test the Email Template or document related scenarios through Test Classes.



Understanding Salesforce Lightning Components Framework

With Dreamforce 14 Salesforce announced its new mobile device development framework called Salesforce1 Lightning. This blog is to get started with Salesforce Lightning by understanding basics of why to use Lightning, What different components are required to be built to get Lightning work.

Following are the key points which are covered in this post
1. What is Salesforce1 Lightning Framework ?
2. Why to use Lightning Framework ?
3. How it works ?

1. What is Salesforce1 Lightning Framework ?
Salesforce1 Lightning Framework is the MVC architecture, UI framework which is primarily used for developing dynamic web apps for mobile and Desktop Customers. Lightning components are all built on top of Aura framework. Aura Framework uses JavaScript at the client side and Java at the Server side. When you use Salesforce1 Lightning Framework you can use Java Script at client side and Apex at Salesforce(Server) end.

2.Why to use Lightning Framework ? 
Following are the number of advantages Lightning Framework has which makes it first choice to choose.

  • 2.1. Out-Of-the-box Component Set : Salesforce1 Lightning Framework provides an entire set of out of the box components which you can directly use without you need to spend time in making them work for all different devices.
  • 2.2. Performance : It uses Stateful client and stateless server architecture which uses Javascript at client side to maintain the state. All the data between the client and server passed only when required and Javascript takes care of values and state of the page. Whenever a page component value if updated it is javascript at client side which takes care of sending that value to server and processing the response so as to update the page. Framework uses JSON to communicate between server and client.
  • 2.3. Faster Development : With in-built support for a large number of ready to use components which works on different devices. It also provides multi-tier component parallel working where you can built the client side component independent of server logic which makes it easy and fast to develop.
  • 2.4. Event Driven Architecture : Uses an event-driven architecture for better decoupling between components. Any component can subscribe to an application event, or to a component event they can see.

3. How it Works ?

Lightning component framework uses stateful client side javascript and stateless server which makes it very quick and gives server all the time in the world to serve other requests. Following is the flow when you copy the application URL in the browser and hit enter.



Before I explain the first request flow, let me briefly tell you what are the different components you have to create for creating a lightning application or custom component.

Application (.app) : This is considered to be the main container holding all your components which you can load in application, starting point for building your components.

Component (.cmp): This is the actual component which are self contained and reusable units of app. They mainly represents a reusable section of the UI. They have prebuilt components which you can include and just like the Visualforce pages these components can contains html, css, Javascript, any other custom lightning component and everything that is web enabled. Components interact with their environment by listening to or publishing events. You can register the event listeners here for all the events and components which you think important and needs some processing.

Controller (.js): Controller is the stateful javascript code which gets invoked whenever you change any page values or an event is triggered which this controller registered as listener. It requires three parameters when an event occurs , Component to which this controller belongs, the event that the action is handling and the helper.

Helper (.js): Helper is the javascript code class for storing the reusable code which you want to use between different components. You can use the helpers to call server side controllers and it can also be used as the callback methods which are mainly used to handle the response from the server and how that response will be displayed on the page.

Style (.css): Styles are used for storing your component related styling(css) information.
There are two more components Documentation and Renderer but for understanding the application request flow these are the main components.

So now lets understand the first request call to server when you copy the application URL in the browser.

1. You copy the URL in the browser and hit enter.

2. Salesforce on receiving the first request loads the application/components definition and the lightning component/s definition executed at server end and is then rendered as HTML markup.

3. Salesforce reply to the client request with the rendered HTML markup.

4. On receiving the html markup the client side javascript controller for the lightning component is initialised and it registers all the events which you mentioned at the component definition and attach each event with the helper method.

5. HTML is rendered on the browser and you see the application. From here onwards the client side controller (javascript) listens to all the events on the page and based on the registered one it decides whether to call the server side controller method through the helper class or not.




   

Cross Organization Data Sharing

If you are looking for a mechanism to share data between two organisations for the sake of real time data sharing and don't want to use any third party application or no more code customisation then Salesforce Cross Organisation Data Sharing is the best way to do it.

This is still the pilot project of Salesforce so you will not see any links in shown here in your Production or any other Sandboxes these are only available in Developer Orgs.

Salesforce data from different org can be shared using the cross org data sharing. This is completely different than copying data from one org to another org using Salesforce to Salesforce connections. Consider a scenario where you have two different orgs one maintains the Inventory information and let’s say second org is required to report on the available items from Inventory. In this case both the systems works on the same data. It wont be a best practice to copy the data from inventory system to reporting system just for the sake of reporting. There are other problems also, might be an issue of delay in the copy which might result in the incorrect result of reporting.

Salesforce Cross Org Data Sharing works in the Hub-Spoke mechanism where all the information flows from Hub to all the Spoke.


Hub-Spoke Topology

Hub - is the org which contains the data we want to share
Spoke - is the org which will use the shared data from Hub. Data resides only in Hub and is shared (displayed) in all the Spoke. No data is copied to Spoke. You can have one Hub working as Spoke for other data type and vice-versa.

Let's get started with a simple data sharing of Accounts between two orgs. For doing so we will have to

1. Configure Hub to share the data
2. Configure Spoke so as to access the shared data from Hub
3. Write the Query to fetch the data

Following is my Hub org where I have Account data which I want to share with other Orgs.

1. Configure Hub to share the data 
Go to Setup --> Data Management --> Cross-Organization Data --> Hub Configuration
Click on New button. Now enter the Hub Name and Unique Name as shown below and check the checkbox against Constrained.


Selecting Constrained checkbox makes sure that whenever you un share the shared object it will show you an error message.

Once you click on Save you will see Hub Details with two more sections Objects and Fields and Spoke Connections.

Go to Objects and Fields Section and click on Edit button, you will see list of the Objects you can share. (Currently you can share Account and Custom Objects Only.) Select Account and click on Save.


Now click on Account under the Objects and Fields and choose the fields you want to share. Please keep in mind Salesforce at this moment does not allow you to share the user related fields like ownerid, createdBy fields. Once you select all the fields you want to share click Save.


Now goto the Spoke Connections Section and click on New Connection button. Here you will be asked to enter the connection name. After entering the name when you click on Save, Salesforce will show a long text which you can use as a code from Spoke to connect to this Hub.


2. Configure Spoke so as to access the shared data from Hub 
Now logon to your Spoke Org and go to.

Setup --> Data Management --> Cross-Organization Data --> Spoke Configuration and click on New XOrgSpoke button.

This will ask you for the Object Label and name, enter the values and click Save. After Save you will see Accept Invitation button, click on this button to create a connection between Hub and Spoke. Here you will have to provide the long text from Hub to connect. On entering the long text system will try to connect to Hub as shown below in the Status.


Once the connection is established you can sync the data by clicking on Sync with Hub button on the Spoke Configuration page. Once the sync is complete you will see all the objects shared from Hub are shown under the Proxy Objects section as below.



Click on Account and you will see all the fields which we shared on the Hub for Account object.

3. Write the Query to fetch the data
Now we will try to test the Connection by writing the SOQL to fetch the records and will test it. Open the Developer Console and write the following query to fetch the records.


Now test the query result. You can find more details from Salesforce Help here .




On my way to DreamForce14 !!!!

Hello Friends,

On my way to the Salesforce Dreamforce14 !!!

Meet you there !!!
















Look out for more updates on Dreamforce14 here .....