Monday, February 29, 2016

Admin: Salesforce Audit Trail...

Have you ever had to work with people who did not document their changes or claimed to work only in Production environment etc?

Yes, while hard to believe, I have worked with such people. While I am very meticulous in documenting my changes, when it comes time to migrate you run into this problem of not knowing what your colleague has done.

Solution

Enter Setup Audit Trail. 

This option is available under:

  • Setup-Security Controls--View Setup Audit Trail


This allows you to see what other developers are doing. You can also download 6 months worth of history in a CSV file and review.

While not a perfect solution, this is much better than not knowing what to migrate
or trying to migrate to testing envs and then failing ChangeSets during Validates or Deploy.


Develop: Considerations and Debugging options when implementing API based integrations.....

Salesforce allows you to integrate using a variety of options. One such way is thru API's: native as well as Custom API's can be leveraged for integrating two systems.

Considerations

For a 1000 license organization, you have a limit of making 1000 x 1000 calls in a 24 hrs period.
This should be one of your design considerations before selecting this method of integration amongst other things.

Note: you can always purchase additional API's.

Now, you implement an API based integration and things start to fail in UAT or Production.

Debugging 
There are some options to debug:

a) Go to Company Profile and note the API Usage last 24 hrs: Salesforce itself uses API's internally which counts against this limit.

b) To find details of which User is consuming these API's head to Reports; Salesforce provides a canned report called API Usage last 7 days in the Admin reports folder. This will give you a certain amount of granularity over option a).

If option b) does not help you then you can request a report from Salesforce on API usage which tells you exactly which transaction ID caused repeated calls to be initiated from external systems.

Happy Debugging !!!

UI: Finding Company Licenses, API Requests per 24 hrs and Used Data space information...

To find License related information, go to Set Up--> Company Information--Company Profile.

You should see a section for User Licenses which lists general set up details with respect to your Org
and License related details.

Used and Remaining Licenses

If you are working on integrating Users from external systems then you might need to know from time to time how many licenses have been consumed and how many are pending.

As you create new users thru UI or Integration, you will see the Used Licenses count go up.

Users cannot be deleted in Salesforce, they can only be Inactivated. So, to get your licenses back you need to Inactivate them and you should see the count for Remaining Licenses go up.

API Requests

You should also see a field for API Requests (Last 24 hrs) which tells the number of API calls made for last 24 hrs. This is one place you can track the usage in situations where you are implementing an API based integration or having issues in Production. 

Typically, you get 1000 API calls per license. So, if you are small org with say 300 licenses then you are allowed 300* 1000 = 300,000 API calls per day.

Used Data Space

This is another attribute you can review from time to time to see how you are doing on the data usage front.

Sunday, February 28, 2016

UI: Launching Standard Forms with predefined values

From time to time, you come across requirements which require you to launch a SF form with values pre-populated say from formulas.

Solution

Every Object has a code in Salesforce and every field has an ID.
Using the combination of 2 along with the instance URL will help you launch
the page.

Create a custom button under the desired object.
Place it on the desired page; set it to execute Javascript.

Place a URL as follow and we will deconstruct what it means:

https://xxx.salesforce.com/a0m/e?CF00NZ0000001kUmV={!Case.Related_Account__c}&00NZ0000001gnrk={!Case.Account_Cost_Center__c}&CF00NZ0000001gnsT={!Case.CaseNumber}&retURL=/{!Case.Id}


https://xxx.salesforce.com  -- is the instance URL

a0m - stands for the object code for your object. One way to find it click on the screen tab for your object and note the URL; it will look something like this https://xxx.salesforce.com/a0m/o and that is what gives you the object ID or code

00NZ0000001gnrk  - stands for the field id, one way to find it is go to your object definition under setup and then click on the field hyperlink. From the URL, please locate the field ID

{!Case.Account_Cost_Center__c} - value that you need to populate the field with

For picklist fields; put the literal 'CF' before the field ID; see example above CF00NZ0000001kUmV={!Case.Related_Account__c}

Another way of pre-populating fields would be of course to write some kind of a pre-insert trigger but occassionally you can get away with this kind of a hack depending on your situation.

DataLoader: Loading Data Values using TXT files in Salesforce

Occassionally you might run into a situation where DataLoader will not work for you to load data in Salesforce. DataLoader typically works with only CSV files.

XL has a limitation of showing data in CSV after I think 15-16 chars, so if you want to load CreditCards or Gift cards which have 16 digits from a CSV file then you end seeing exponential numbers in XL i,e, something like 6.05E+9.

Solution

You can use the power of APEX to load data in TXT file format.

You need 2 things:
a) a Visual Force form to be able to select file from your desktop
b) a Controller Class to load data

//Start of Visual Force
<apex:page controller="XXX">
<body>
<center>
    <b><font size="15"><h1>Gift Card Master Data Load Form</h1></font></b><br/>
    <font size="2">1. Download the Vendor file and format in the appropriate txt file format.</font><br/>
    <font size="2">2. Click on the 'Choose File' button file below and select the file.</font><br/>
    <font size="2">3. Click on the 'Load Cards Data' to load data.</font><br/>
   
<p/>

<apex:form >

<apex:tabPanel >
<apex:tab >
<apex:inputfile value="{!fileBody}"/>
<apex:commandButton value="Load Cards Data" action="{!readContent}"/>
</apex:tab></apex:tabPanel>


</apex:form>
</center>
</body>
</apex:page>

                   
//End of Visual Force

Next, is the class to load the file:

//Start of Controller Class
public with sharing class XXX{
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    public blob fileBody { get; set; }

    String[] filelines = new String[]{};
    List<ObjName> ObjVar1;
   
public void readContent() {
      nameFile=fileBody.toString();
        filelines = nameFile.split('\n');
        GCtoupload = new List<ObjName>();

    for(Integer i=0;i<filelines.size();i++)
    {
   
      String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
           
            ObjName Var= new ObjName();
            Var.Fld1= inputvalues[0];
            Var.Fld2= inputvalues[1];      
        
        ObjVar1.add(Var);
       
    }

   try{
   insert ObjVar1;
   
   } catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the file and try again later.');
            ApexPages.addMessage(errormsg);
        }   
}
        
}
//End of Controller Class

Here is the file format I used:

D000493500555389448,10.23,
D006493500555389455,11.23,
D006493500553798426,10


Saturday, February 27, 2016

DataLoader: Understanding External ID

Recently, I had to integrate data using file based approach  with an external legacy system. The frequency of this integration was supposed to be daily. Circumstances, did not allow for the legacy system to store Salesforce ID in their system and send it in their extracts.

So, how do you know at your end whether to insert or update when using DataLoader?

Solution

In comes External ID, it allows you to mark a field as unique in Salesforce; prevent duplicate records from getting created and allows the DataLoader to decide whether to insert or update a record.

Launch DataLoader and select the Upsert Operation to be executed, select your object and for the field to be used for matching point to the External ID field.

Salesforce will use the External ID field as a key and decide whether to update or insert.
You can have multiple External ID fields for an object. You can also use it against lookup fields to populate ID from your lookup object. It is case insensitive unless you select the Case sensitive option when defining the field.

DataLoader: Inserting NULLS using DataLoader

If you need to insert null values using DataLoader, then merely having null values in your excel sheet for the desired column will not work.

Launch your DataLoader; go to Settings and mark the checkbox

"Insert Null Values"

Launch the desired operation and validate your results against your column.