Monday 7 October 2013

Quick Fix :- How to build the URL to launch an Email template via Standard Screening



Case Study:

How to Create an email template that will Auto Fill the account, and primary contact when selected from the Send Email from the Opportunity Activity History panel.

Clicking on Send Email from there gives a blank window to send email from - How to fill them with information from the record which they are coming from

Solution :-

One click java-script to Send an email using standard emailing screen. See below :-

location.replace('/email/author/emailauthor.jsp?retURL=/{!Account.Id}&p24=<To Email Address>&template_id=<email template id>&p3_lkid={!Account.Id}&p3={!Account.Name}&p26=<from email address>&p5=&save=0');

Let us quickly analyze the URL Parameters :-

p2_lkid = it is "Email TO" Field Code , associated only with Contact ID of Contact Standard Object, populares the Contact in To Field of Email.

rtype = record type 001 means Account and so on

p3_lkid = whatId ( hidden lookup field) it is must if the merge fields are there in template

p24 = additional email to be added as addional

retURL = returning URL

p5 = stops adding more BCC

p26 = to change the domain from which you are sending

template_id - Email Template Id, It can have merge fields.

save = 0, means send the email automatically and return to retURL ,( leave it if you just need to see the screen with populated fields)

The aforementioned fields are standard fields provided from Salesforce side. These arent customizable but you can specify values for this as per your need and requirements. You can give merge fields values over there and that may help.

Monday 16 September 2013

Crunch Code Clear Field using JavaScript on Visualforce Page

Simple Code Crunch to Clear Fields , clicking a Link.


A smiling code which takes the Id of the Field which you want to clear and clears it with the event.. Hope you like it.


<apex:page standardController="Contact" id="page">
    <apex:form id="frm">
        <apex:pageblock id="pblck">
            <apex:pageblockSection id="pbSectn" >
                <apex:pageblockSectionItem id="pbSitemLookup">
                    <apex:inputField id="accountLookup" value="{!Contact.AccountId}"/>
                </apex:pageblockSectionItem>
               
                <apex:pageblockSectionItem id="pbSitemLastName">
                    <apex:inputField id="contactLastname" value="{!Contact.LastName}"/>
                </apex:pageblockSectionItem>
               
                <apex:pageblockSectionItem id="pbSitemLink">
                    <b><a href="#" onClick="clearValue()" > Clear </a> </b>
                </apex:pageblockSectionItem>
            </apex:pageblockSection>
        </apex:pageblock>
       
        <p> <apex:commandButton action="{!Save}" value="Save" id="cmdSave"/> </p>
    </apex:form>
   
    <script>
    function clearValue()
    {
    document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLookup:accountLookup}').value = '';
    document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLastName:contactLastname}').value = '';
 
    alert();
    return false;
    }
   
    </script>
   
   
</apex:page>



Thank You

Tuesday 10 September 2013

Hide Recycle Bin from Home Page Layout : 2 Minute Recipe



Salesforce doesn't provide specifications to remove Recycle Bin from Home Page.But there are situations which demands that the Recycle Bin shouldn't be shown over the Home Page. In such adverse situations JavaScript is our Best Friend.


First Let me tell you about this Dustbin of Salesforce.

The Recycle Bin link in the sidebar lets you view and restore recently deleted records for 15 days before they are permanently deleted.You can read more from here.

Follow the following steps to Hide the Recycle Bin.

1. Click on Name > Setup > Customize > Home > Home Page Components.
2. Click on New to add a New Custom Component. 


    Give it a unique name of your choice and Select HTML Area and Continue.

    Make sure that you have checked WIDE COMPONENT and SHOW HTML Checkbox.


    Paste the Code provided.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<span id="hideMyParentsp">
</span>
<script>
$(document).ready(function() {  $('#sidebarDiv #hideMyParentsp').parent().parent().hide();      });
</script>

<script type="text/javascript">
window.onload = function(){
var x=document.getElementsByTagName("img");
for(var i=0;i<x.length;i++) {
  if(x[i].title=='Recycle Bin')  {
     var dtag = x[i].parentNode.parentNode.parentNode; dtag.style.visibility='hidden';
      }
 }
var xx=document.getElementsByTagName("span");
for(var ii=0;ii<xx.length;ii++) {
  if(xx[ii].innerHTML=='Recycle Bin')  {
 xx[ii].style.display='none';
  }
 }
 };
 </script>


    Click on Save.

3. Next we need to add this component on Home Page Layout.For this Follow the following Steps
   
    Click on Name > Setup > Customize > Home > Home Page Layout.

    Select "Edit" for your Layout from which you want to remove Recycle Bin.
    Check the Component which you just created in Wide Column Display , Click Next

    Click Save , Additionally you can see the preview.


  You can see the changes in your Home Page. Recycle Bin is No More. You can say that his soul is with us [as it is just hidden] but his body left the mortal world.

  I also lost my recycle bin the same way. write , comment me for some condolence at       gautam.salesforce@gmail.com

  Happy Hiding.

Thursday 8 August 2013

Batch Apex & CSV Parsing - I am Lovin'it !!


Situation :

I have a CSV File with 3 Fields Lead ID , Yes|No Field and Operator Name.
Without Using Data Loader I need my Data Entry Team to Upload this File  and Leads get updates with these values in the respective fields.



Solution :

Perhaps , Data Loader is the Mirror Cracking Solution. But you cannot get all the happiness at once.

Making the Data Entry team familiar with Data Loader and expecting that they will do correct is like expecting a lion not to eat you all because you are a Vegetarian.

So , Clear Cut My Process was turned up to Batch Apex CSV Parsing . Yes ! You Heard It Correct Batch Apex CSV Parsing .

So , I went to my Manager with this serving on Plate...

I will create a Visualforce Page with a Browse Button.
When a CSV File with Correct Format is Uploaded from there.It will call an controller which will call the Batch Process . The Batch will call a class which will insert records from the values which it gets from another class. Make Sense ?

His words "Sounds Delicious !! "

So , I started upon it .. Here are the ingredients

1.  Page -- BatchUpdateLeads

/* This will be the Visualforce Page with the Browse Button. /*

2. ctrlUpdateallrecFromCSV

/* This will be the Extension which will be called from the Page. /*

3. BatchProcessor

/* Called from the Extension, This is the Actual Batch Process. /*

4. BatchSObjectFeeder

/* This will be an Input for the Batch Apex in its Start Method. /*

5. ctrlAdddataFromCSV

/* This will be the called from the Batch Apex. "InsertValues"  Method will be called. Also , This is the class responsible for Saving the Records in Salesforce. /*
6. clsAdddataFromCSV

/* This is the Class called from ctrlAdddataFromCSV , The main process of this is to parse the excel sheet  . /*



Get the Code from Here ..
Disclaimer : This is a chain of classes as I respect OOP Concepts.


Hope it works well for you all !

Happy Batch Update !! :-)


Friday 19 July 2013

The Story of 'ASC' & 'DESC' in SOQL


Recently , I was trying to implement the masterpiece of JavaScript & Jeff Douglas > Dynamic Search Functionality which was getting parameters and searching the records in real time.

I was doing well but then I stuck at a issue pointed by my MIS head stating that Sorting doesn't work for the Null records and I was asked to fix this so that whenever we sort on the basis of a column , the records with null values should not come over first , they should be placed in last.

I was sorting on the basics of Registration Number but I was not getting all the null records in first. It was killing me and my time.

I was using database.query to give get the records sorted when we click on label Registration Number:-

SELECT  Id, Reg_Num FROM Courses__c order by Reg_Num DESC.




So I carved out a path with the the best friend of all developers "Google".

Keyword : NULLS LAST

SELECT  Id, Reg_Num FROM Courses__c order by Reg_Num DESC NULLS LAST


Here is what I got the explanation...


The Default Sorting of NULLs is DBMS dependent. Some of them sort at the end and some at the beginning. Salesforce does it in beginning. So, only way to ensure this is to use NULL FIRST/LAST if the DBMS supports it.

In standard SQL (and most modern DBMS like Oracle, PostgreSQL, DB2, Firebird, Apache Derby, HSQLDB and H2) you can specify keyword NULLS LAST or NULLS FIRST.

The usage of isnull() or other functions is a workaround for the missing support for NULLS.

So , I wrote this down so that I could save someone's life and important time which he would spend while consulting the best buddy "Google".

Hope this writing helps you in the thing which you were looking for.

Happy Sorting !