function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sairam adminsairam admin 

I need Total no of contacts and Accounts in Home tab?

Dear Friends,

I need to see how many contacts and Accounts in my organisation in Home tab with out use Vf.

Note:Only no of candidates only not view of all candidates.



Please tell me friends.

 
Best Answer chosen by sairam admin
PratikPratik (Salesforce Developers) 
Hi Sairam,

Here is code:

1.Controller:

Public class counter {

  integer totalacc;
  integer totalcont;

   public integer getacc() {
   
totalacc=[select count() from account];
return totalacc;

   }
   
   public integer getcont() {
    totalcont=[select count() from contact];
    return totalcont;
   
   }
       
 }


2.VF Page:


<apex:page controller="counter" showChat="false" showHeader="false" setup="false" sidebar="false">

<apex:form >

    <apex:pageBlock title="Here are the counts">
    
    <apex:pageBlockSection title="Number of Accounts:">
    
    <apex:outputText value="{!acc}"></apex:outputText>
    </apex:pageBlockSection>
    
    
    <apex:pageBlockSection title="Number of Contacts :">
    <apex:outputText value="{!cont}"></apex:outputText>
    
    </apex:pageBlockSection>
   
    </apex:pageBlock>
</apex:form>
</apex:page>

3. Include this VF page as Home page component and add it on home page layout.

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.

All Answers

PratikPratik (Salesforce Developers) 
Hi Sairam,

Here is code:

1.Controller:

Public class counter {

  integer totalacc;
  integer totalcont;

   public integer getacc() {
   
totalacc=[select count() from account];
return totalacc;

   }
   
   public integer getcont() {
    totalcont=[select count() from contact];
    return totalcont;
   
   }
       
 }


2.VF Page:


<apex:page controller="counter" showChat="false" showHeader="false" setup="false" sidebar="false">

<apex:form >

    <apex:pageBlock title="Here are the counts">
    
    <apex:pageBlockSection title="Number of Accounts:">
    
    <apex:outputText value="{!acc}"></apex:outputText>
    </apex:pageBlockSection>
    
    
    <apex:pageBlockSection title="Number of Contacts :">
    <apex:outputText value="{!cont}"></apex:outputText>
    
    </apex:pageBlockSection>
   
    </apex:pageBlock>
</apex:form>
</apex:page>

3. Include this VF page as Home page component and add it on home page layout.

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
This was selected as the best answer
sairam adminsairam admin
Hi Pratik,
Almost all Ok .....when after adding to home components it's showing direct vf coding ....


don't main can u please give me brief steps for adding vf in home components.
Homepagecomponents
PratikPratik (Salesforce Developers) 
Hi Sairam,

Once you are done with saving Controller and VF page, Go To:

Setup->customize->Home->Homepage Components->New -> Select Visualforce Area and then select VF page.

Screenshot:

 User-added image
Here "showcount" is the name of my VF page.

Then add this component on home pagelayout at appropriate position.

It looks like this:

Screenshot:

User-added image


Thanks,
Pratik


 
Santosh Kumar YadavSantosh Kumar Yadav
Very nice answer by Pratik.