Friday, December 9, 2011

Cool links for salesforce.com tools and best practices

I was going through the Best practices for force.com and Trigger template. It will be really helpful if we could follow it in our code.

You can also find lots of interesting tools for salesforce.com here.

Found this awesome IDE and data loader on the cloud !!! - Workbench . I would have loved to have metadata export on this. If anyone knows a tool not an app through which we can export metadata (not like an XML) more like a spreadsheet which can be used for documentation and data mapping please drop a comment here.

Finally Vote for all the ideas in this link. These are all the features worth having in SFDC.

There are many a times where we need to mimic a standard page through VF. Creating them to mimic it is a hard thing. But it can be done with a single click , whole code gets generated. You can check that out here. Pretty cool stuff aint it.

Tuesday, October 18, 2011

Javascript to select all checkboxes in visualforce page

I needed to develop a custom visualForce page which would hold a page block table which would contain a checkbox and details of a custom object based on which user can select and click on buttons to perform some operations.

I wrapped the custom object record and check box in a wrapper class. I needed a simple functionality when the header checkbox is selected or deselected accordingly all the checkbox will get selected or deselected accordingly. So i looked into community and first result community gave is this(controller way). It involved calls to back end and as a result functionality is little slow.

So I went for a Javascript solution which would provide a faster,elegant and much simpler way.Here is the VF code which was used in the page above.

<apex:pageBlockTable value="{!wrapreportsobj }" var="w" id="Selected_PBS">
<apex:column ><apex:facet name="header">
<apex:inputCheckbox onclick="checkAll(this,
'checkedone')"/>
</apex:facet>
<apex:inputCheckbox value="{!w.selected}" id="checkedone"/></apex:column>
<apex:column ><apex:facet name="header">Id</apex:facet><apex:outputfield value="{!w.rep.id}"/></apex:column>
<apex:column ><apex:facet name="header">Name</apex:facet><apex:outputfield value="{!w.rep.name}"/></apex:column>
</apex:pageBlockTable>

Note that I have set the id of the checkbox as checkedone and while clicking on header checkbox it calls a javascript function  checkAll. Giving an id will segregate all the checkboxes in the table. Here is the javascript which would handle the selecting and deselecting all of the checkboxes which has id checkedone in it.


<script type="text/javascript">
    function checkAll(cb,cbid)
        {
            var inputElem = document.getElementsByTagName("input");                    
            for(var i=0; i<inputElem.length; i++)
            {            
                 if(inputElem[i].id.indexOf(cbid)!=-1){                                       
                    inputElem[i].checked = cb.checked;
                }
            }
        }
</script>


Friday, September 16, 2011

Migrating Opportunity line item

This post is a continuation of my earlier post on Product, Pricebook and Pricebook entry.Opportunity Product(line item) is a junction object between opportunity and pricebookentry table.

List of fields in opportunity products
  • ID
  • OPPORTUNITYID
  • PRICEBOOKENTRYID
  • CURRENCYISOCODE
  • QUANTITY
  • TOTALPRICE
  • UNITPRICE
  • LISTPRICE
  • SERVICEDATE
  • DESCRIPTION
Fields indicated in red are mandatory fields and fields which are in grey are read only. Unit price field specifies the price at which the product was sold. List price is the price of the product in the pricebook. use either one of the totalprice or unitprice field while loading.The other field will be automatically calculated based on quantity while loading. Refer to my previous post for inserting a new pricebook entry/ Exporting existing pricebookentry. Prepare a csv file with all these data.Also optional fields like service date and description can be filled for CSV. Use data loader to insert data. Click here for Sample CSV

Notes on loading

  • pricebook entry should be in the same pricebook that is assigned to the opportunity.  The pricebook name can be found in pricebook2id field in opportunity
  • If the opportunity does not have an associated pricebook2, the API automatically sets the pricebook on the opportunity if the line item corresponds to a Pricebookentry in an active Pricebook2. Changing the pricebook association would delete existing opportunity line items.
  • Creating an OpportunityLineItem increments the OpportunityAmount value by the TotalPrice of the OpportunityLineItem. Additionally, inserting an OpportunityLineItem increments the ExpectedRevenue on the opportunity by the TotalPrice times the opportunity Probability.
  • The OpportunityAmount becomes a read-only field when the opportunity has line items.
  • If multi-Currency is enable for your organization, Choose a price book that contains products with the same currency as the opportunity. pricebook entry currency code should match opportunity currency code.You cannot update the CurrencyIsoCode field on the opportunity if line items exist.

Thursday, September 8, 2011

Escalation Queues and workflows.

I recently had a need to escalate a case which has status value new and in a queue for 2 hours, So that if nobody picks up the case it would be escalated to manager.

It took me about a day to figure out how to write the entry criteria to check whether the case is in a queue or assigned to a owner. salesforce Ids has a certain pattern across all org for certain objects. so by that i figured out that users always started with 005 and group and queue always started with 00G.

Also i had to use 'Formula evaluates to true'  instead of easy 'Criterias are met' as owner ids are not available in this. Here is the formula i used.

AND(  ISPICKVAL( Status ,"New") , BEGINS(OwnerId, "00G") ,not( IsClosed ) )  

 Now coming to other stuffs
  
Realized that Case Escalation cannot trigger a workflow. Case escalation would cause an 'isEscalated' flag to be checked. I assumed that it can be used to trigger a workflow. i used the same entry criteria in workflow as in the escalation rule and used time dependent action instead. Thankfully my use case needed field updates only for the first time the case is escalated.


Couple of more things changes to formulae field would not trigger the workflow and so also field update from a workflow. This link might be useful Workflow considerations

If you could find if salesforce has documented somewhere which all will trigger a workflow, Let me know 

Tuesday, August 23, 2011

Loading Converted Leads

      When you are migrating data from one system to another there will be a need to load the leads as converted as they would have been already converted in the source system.

    First step is to raise the case with salesforce.com to open up the audit fields for your organisation. The fields CONVERTEDACCOUNTID, CONVERTEDCONTACTID, CONVERTEDOPPORTUNITYID and CONVERTEDDATE will not be visible while inserting or updating by default.

Once the salesforce allows you to load these system fields you can start your process.

Steps for Loading
  • Firstly, Load Account, Contact and Opportunity which needs to be associated with the converted lead.
  • Next prepare a csv files with information of lead and get the ids from previous step and load it into the appropriate converted fields of file as mentioned above.
  • The field Isconverted should be set to true
  • Insert, Update or Upsert the leads as necessary.
    Things to consider while loading

    • Converted Account is mandatory . Converted contact and opportunity is not mandatory. converted contact and opportunity need not belong to converted account.
    • You cannot see the information of converted leads. If you go to the lead detail page through its id you will see information on Converted date, Converted account, Contact and opportunity whichever was mapped. Only way to extract the information is through API
    • Lead conversion mapping will not be respected.For eg Lead description is mapped to contact description and when u load the converted lead with description it will not be carried over to the converted contact.
    • Converted date if not mapped will give value This lead was converted on {0} on lead detail page. If you need to enter converted date make sure you also enter created date . Otherwise it would error out as created date would be defaulted to now which will be at future date when compared to converted date.
    • Lead triggers and validation rules will be fired.
    • Converted Leads cannot be updated but can be deleted 
    click here to have a look at the sample csv file.
      If you have any questions please post it in comments section