Saturday, 30 November 2013

Showing image in the ms-word document from vf page of Salesforce.





Hi guys,


I am writing this because one of my friend get stuck in this requirement, I am also get surprised why the image is not showing in the MS-Document,

then finally I got its solution.

Here the code for the VF-Page,

   <apex:page sidebar="false"
            showHeader="false"
            contentType="application/msword#Test.doc"
            cache="true">

<head>
                        <meta http-equiv="Content-Type" 
                               content="text/html;charset=UTF-8" />
</head>

<img src="Document_URL" />
    </apex:page>

--> Document_Url is the url of the your image uploaded in the Document object of Salesforce.
--> cache = "true" for IE.

Hope  it helps...
Happy Coding...

Thanks,
Anurag Jain.

Tuesday, 26 November 2013

Shows Standard Salesforce Report Chart to Standard Salesforce Sidebar.





Hi guys,

   I’m writing this post because it may be the requirement of your clients and their is not direct way to show chart on Standard sidebar of salesforce.

This is actually the new type of requirement form one of my client, he wants to see the report chart on every page of its salesforce account, so solve it in this way to put chart on sidebar and show make visible the sidebar on every page.

Basically i opens an "iframe" on the html of Home Page Components.

So here the steps:
1.      Create a Report chart according to you requirements, make sure that this chart is of Tiny in size so that it can easily come in sidebar window.
2.      then go to Setup > Customize > Home > Home Page Components > Custom Components > New,
then choose the “HTML Area” then next and selects Narrow(Left) Column, click on show html check box on the right  corner and put the following code in it:

<iframe src="https://cs14.salesforce.com/Report_Id" scrolling="no" height="620px" width="150%" style="margin-top: -445px; margin-left: -70px;"/>
 
3.      Now add this component to the home page layout
(Note: make sure you assigned the page to the profile in the Home Page Layout.)
Now you can see that report chart is showing to the home page side bar as,

If you want to show it on every page then,
Go to Setup > Customize > User Interface > Sidebar
then true the “Show Custom Sidebar Components on All Pages” check box and save it,

That’s it, now the report chart is showing on every page of you Salesforce where sidebar is visible as:

Happy Coding…:)

Thanks,
Anurag Jain,



Friday, 22 November 2013

Run Once logic for avoiding multiple or recursive calling of trigger in Salesforce


             
Hi guys,
This is my first blog, so please correct my if I am wrong somewhere,
Here the simple but tricky question asked in many interviews of salesforce because it’s a common scenario comes many times that’s why I’m writing this,

Suppose you have to update a record in a trigger with after update event then what happens???

Here example:
trigger updateAccount on Account (after update) {
     List<Account> accList = new List<Account>();
     for (Account a : Trigger.new) {
        // some logic……
        //…………………………….
          accList.add(a);
     }
     update acclist;
}

If you execute the above code then, the trigger is recursively called and thoughts exception
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, updateAccount: maximum trigger depth exceeded 

Because you trying to do updation in trigger which is also updating same record so it called itself again and again and again upto its limit,

Here the solution of this problem,
1         1.  Make a public class.
2      2.    In that class take a static Boolean variable.
3      3Then create a static method, which has if statement which returns true first time only.

 Code:

-->> A class with static boolean variable and method:-


public class runOnce{
    public static Boolean firstRun = false;   
    public static Boolean run(){
        if(!firstRun){
            firstRun = true;
            return firstRun;
        }
        return false;
    }
}

-->> Now change in trigger,

trigger updateAccount on Account (after insert, after update) {   
     if(runOnce.run()){
         List<Account> accList = new List<Account>();
         for (Account a : [Select ID from Account where Id in :Trigger.new]) {
        // some logic……
        //…………………………….
              accList.add(a);
         }
         update acclist;
     }
}

Hope it helps, Happy Coding...:)

Anurag Jain