Friday, January 17, 2014

Dealing Large Data and Salesforce


Best Practices

This section lists best practices for achieving good performance in deployments with large data volumes.

The main approaches to performance tuning in large Salesforce deployments rely on reducing the number of records that the system must process. If the number of retrieved records is sufficiently small, the platform might use standard database constructs like indexes or de-normalization to speed up the retrieval of data.

Approaches for reducing the number of records include:
  • Reducing scope by writing queries that are narrow or selective. 
For example, if the Account object contains accounts distributed evenly across all states, then a report that summarizes accounts by cities in a single state is much broader—and takes longer to execute—than a report that summarizes accounts by a single city in a single state.
  • Reducing the amount of data kept active
For example, if your volume of data is increasing, performance can degrade as time goes by. A policy of archiving or discarding data at the same rate at which it comes into the system can prevent this effect.

Scenario I:

Data Aggregation

Situation

The customer needed to aggregate monthly and yearly metrics using standard reports. The customer’s monthly and yearly details were stored in custom objects with four million and nine million records, respectively. The reports were aggregating across millions of records across the two objects, and performance was less than optimal.

Solution
The solution was to create an aggregation custom object that summarized the monthly and yearly values into the required format for the required reports. The reports were then executed from the aggregated custom object. The summarization object was populated using batch Apex.

Scenario II:

Custom Search Functionality

Situation

The customer needed to search in large data volumes across multiple objects using specific values and wildcards. The customer created a custom Visualforce page that would allow the user to enter 1–20 different fields, and then search using SOQL on those combinations of fields.

Search optimization became difficult because:
  • When many values were entered, the WHERE clause was large and difficult to tune. When wildcards were introduced, the queries took longer.
  • Querying across multiple objects was sometimes required to satisfy the overall search query. This practice resulted in multiple queries occurring, which extended the search.
  • SOQL is not always appropriate for all query types.

Solutions

The solutions were to:
  • Use only essential search fields to reduce the number of fields that could be searched. Restricting the number of simultaneous fields that could be used during a single search to the common use cases allowed Salesforce to tune with indexes.
  • De-normalize the data from the multiple objects into a single custom object to avoid having to make multiple querying calls.
  • Dynamically determine the use of SOQL or SOSL to perform the search based on both the number of fields searched and the types of values entered. For example, very specific values (i.e., no wild cards) used SOQL to query, which allowed indexes to enhance performance.

Tip: Searches that contain a leading wildcard are better performed by SOSL than SOQL.


Scenario III:

Indexing with Nulls


Situation

The customer needed to allow nulls in a field and be able to query against them. Because single-column indexes for picklists and foreign key fields exclude rows in which the index column is equal to null, an index could not have been used for the null queries.

Solution

The best practice would have been to not use null values initially. If you find yourself in a similar situation, use some other string, such as N/A, in place of NULL. If you cannot do that, possibly because records already exist in the object with null values, create a formula field that displays text for nulls, and then index that formula field.

For example, assume the Status field is indexed and contains nulls.

Issuing a SOQL query similar to the following prevents the index from being used.

SELECT Name
FROM Object
WHERE Status__c = ''

Instead, you can create a formula called Status_Value.

Status_Value__c = IF(ISBLANK(Status__c), "blank", Status__c)

This formula field can be indexed and used when you query for a null value.

SELECT Name
FROM Object
WHERE Status_Value__c = 'blank'

This concept can be extended to encompass multiple fields.

SELECT Name
FROM Object
WHERE Status_Value__c = '' OR Email = ''


Salesforce 1 | How to get started with Salesforce 1 platform Development

Salesforce have unveiled Salesforce 1, a new CRM platform to better connect with customers and to keep up with latest trends to reassure public that they are not falling behind. Seemingly there are lots of phenomena like Social, mobile applications, wearable devices and cloud computing,  so clearly business are looking for more tactical solution that meet the target implementations. Salesforce revamped the platform by consolidating all internet based technologies into one single service that companies can use to built out their offering and spend more time and focus on customer.
Salesforce 1, incorporates numerous API all into one platform with additional streaming API. Now most important things here to note is Salesforce is free for all user and even for developers free account. Clearly all the existing users will automatically be updated.

Design Your First Mobile Application 

Go to setup on your developer instance and type in 'Salesforce1' in quick search box and type in Salesforce 1 to make sure you have enable Salesforce1 instance as shown here



















To get started, you need a sample application and this application is pre-created by Salesforce to give you a vague idea of how the application is designed and can be used. Jump here to steps shown in this document in the link below

* These are steps mentioned over on  Salesforce 1 documentation  :

Install Salesforce 1 Application Package to Quick Start 


You might be familiar with the Warehouse app if you’ve gone through the tutorials in the Force.comWorkbook. We took the Warehouse data from that guide and added a few extra things to it to help show you what Salesforce1 can do.
  • Go to www.salesforce.com and log in to Salesforce using your Developer Edition credentials.
  • Open a new browser tab or window, and navigate to https://github.com/forcedotcom/Salesforce1-Dev-Guide-Setup-Package. Do this in the same browser that you used to log into your developer organization with.
  • Open the README file.
  • Click the bit.ly link in the README file. This is the installation link for the enhanced Warehouse data package. You should be taken directly into your development organization to the Package Installation Details page.
  • Click Continue.
  • Click Next.
  • Click Next.
  • Click Install.
  • Wait for the installation to finish.
  • From the Force.com app menu, select Warehouse.
  • Click the Data tab.
  • Click Create Data.
    All right! The last step is to download the Salesforce1 app, then we’ll be ready to roll.

    Download the Application for Apple/Andriod


    Now you need the device, I am here demonstrating through my iPhone, to get started you need to download the Salesforce1 Application from Apple stone through here

     

    Once you have download the application, you need to install the appplication on your device and login through your Salesforce Credentials like shown in my phone here






























    Pass on credential to login and select the warehouse application on the run and you will this confirmation message once you successfully install the application

    Enough of Administration now lets jump back to development and create a quick visualforce page to see how this work. Salesforce had provided some sample code with required static resource that you have already installed in the platform

    Create a Visualforce Page


    Now we’ll create a Visualforce page and make it available from the navigation menu.
    This Visualforce page references these items:
    • A static resource named googleMapsAPI
    • An Apex class named findNearby
      * Note this visualforce page comes in the package you have just installed 

      Make sure you have Mobile enabled on Visualforce Pages properties


      Open <sfintance>/apex//apex/FindNearbyWarehousesPage.

      Create a New VisualForce Tab

      To take this application to your Salesforce 1 Mobile Application, create a new Visualforce Tab.




      Add the Tab to the Navigation Menu

      Now let us add this tab to Mobile Navigation Menu

      Increase GeoLocation Miles to bring California for Multiple Pins

      N Since I am located in Austin, Texas so 2000 miles from here will bring California location in my Map, go to the FindNearby class and increase the radius



      Test Application on your Phone !