Pages

23 November 2012

Create a Blogger search widget

Blogger Search Gadget not working ! (i had the same issue and noticed this is a common, known issue on blogger.)

I added a search widget to my blog to enable blog search Eureka ! It works like a charm.

Login to your Blogger account.

Layout > Page Elements (elements on the layout). Click on Add a Gadget and select HTML/Javascript.

In the Title field, enter how you would want to call your search ex:"Search blog", etc.; In Content, paste the following code:
<form action="search" name="input" method="get">
<input value="Search" name="q" size="20" type="text"/>
<input value="Go!" type="submit"/>
</form>

22 November 2012

Format Decimal field on Visual force page

A small snippet below shows how we could format a decimal field retrieved from an object via SOQL query.

{!VALUE(TEXT(ROUND(cols.decimal_field__c,0)))} - Formats the data with 0 decimal places.


Tips on Custom Lead conversion Functionality in Salesforce

Apex gives methods to perform custom lead functionality. This is an amazing feature 
that can be leveraged to override the "convert lead" button in salesforce with a VF
page and perform intermediate validations. Here is what i have done:

VF Page action method is leveraged to perform the Validations: 
 
 <apex:page standardController="lead" cache="true" action="{!autorun}"  
 extensions="leadController" >  
 <br/><br/>  
 <apex:messages style="color:red; font-weight:bold; text-align:center;"/>  
 <apex:form >  
 <center>  
 <apex:commandLink value="Redirect to Lead" style="color:blue; font-weight:bold;"   
 action="{!RedirecttoLead}"/>  
 </center>  
 </apex:form>  
 </apex:page>  
 
Controller Code:
---------------- 
 
1:  public class leadController  
2:  {  
3:    Public lead lObj;  
4:    Public Id leadId;  
5:    public leadController(ApexPages.StandardController stdController)  
6:    {  
7:      leadId = ApexPages.currentPage().getParameters().get('id');  
8:      lObj = (leadid == null) ? new Lead():[SELECT Money_Order__c,   
9:      Money_Transfer__c from lead where id =: leadid];  
10:    }  
11:    public PageReference autoRun()  
12:    {  
13:      Database.LeadConvert lc = new database.LeadConvert();  
14:      lc.setLeadId(leadId);  
15:      LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus   
16:      where IsConverted=true limit 1];   
17:      lc.setConvertedStatus(convertStatus.MasterLabel);  
18:      if(lObj.Money_Order__c == true || lObj.Money_Transfer__c == true){  
19:      Database.LeadConvertResult lcr = Database.convertLead(lc);  
20:      System.assert(lcr.isSuccess());  
21:      Id oppId = lcr.getOpportunityId();  
22:      PageReference Page = new PageReference('/'+oppId);  
23:      Page.setRedirect(true);  
24:      return Page;  
25:      }  
26:      else{  
27:      lObj.addError('Lead cannot be converted without Product Selection !');  
28:      lObj.addError('Please Select Atleast One Product');  
29:      }  
30:      return null;  
31:    }  
32:    Public PageReference RedirecttoLead(){  
33:      PageReference Page = new PageReference('/'+leadId);  
34:      Page.setRedirect(true);  
35:      return Page;  
36:    }  
37:  }   

Hope this helps. :)

Access Currency Conversion in Apex

In Organizations with multi-currency enabled, data would be entered in corporate currency. When the users logs in, it is always advantageous to have the data displayed in the users personal currency.

This happens by default when we view a standard detailed page of any record, or on a report, but when we access the data via Visualforce pages, we need to have the currency value not in base currency but the logged in user's currency.

How do we achieve this via Apex, keeping the conversion for current users ?

Apex provides very easy solution to this.

Select Account__c, Type__c, Year__c, UOM__c,convertCurrency(Jan__c),
NOTE: The convertCurrency function can act only on currency fields and returns values in the currently logged in user context.

Hope this helps.