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
Aditya KamdiAditya Kamdi 

Hi All, I am not a developer but more of an admin and I have started in a new organisation and I need to get the number of opportunities that are at a certain stage

Hi All,  I am not a developer but more of an admin and I have started in a new organisation and I need to get the number of opportunities that are at a certain stage i.e "Agency Reserved" and send that value to a VF page where a report is made.
 
public class CompanyDashboardWithOpp_V2
{
	public static string SYD_Subtotal_Reserved_Unit{get;set;}
	init();
	static string STOCK_STATUS_AR = 'Agency Reserved';
	

	public void Init()
    { 
	List<Opportunity> sydney_Reserved_Unit_Opp_Lst = [SELECT Id,Project_Name__r.name FROM Opportunity WHERE (StageName =:STOCK_STATUS_AR)];
	Decimal Stock_Reserved=0;
	for(Opportunity opp : sydney_Reserved_Unit_Opp_Lst)
        {
			Stock_Reserved++;
		}
		
	SYD_Subtotal_Reserved_Unit = String.valueOf(Stock_Reserved); 
	}
	
}

 
devedeve
Hi Aditya,

If you need only count that how many opportunities are there having status 'Agency Reserved' then you can directly run query like this


public class CompanyDashboardWithOpp_V2
{
    public static string SYD_Subtotal_Reserved_Unit{get;set;}
    init();
    

    public void Init()
    { 
        Integer numberOfOpportunity = [SELECT Count(Id) FROM Opportunity WHERE StageName = ''Agency Reserved')];
        SYD_Subtotal_Reserved_Unit = String.valueOf(numberOfOpportunity); 
    }
    
}
Jithesh VasudevanJithesh Vasudevan
What is the error you are getting right now?
Narender Singh(Nads)Narender Singh(Nads)
Hi Aditya,

Try this:
 
public class CompanyDashboardWithOpp_V2
{
    public static string SYD_Subtotal_Reserved_Unit{get;set;}
    init();
    

    public void Init()
    { 
        Integer numberOfOpportunity = [SELECT Count() FROM Opportunity WHERE StageName = 'Agency Reserved'];
        SYD_Subtotal_Reserved_Unit = String.valueOf(numberOfOpportunity); 
    }

Let me know if it helps
Thanks
 
Ajay K DubediAjay K Dubedi
Hi Aditya,
Please try the code below.

public class CompanyDashboardWithOpp_V2
{
    public string SYD_Subtotal_Reserved_Unit{get;set;}
    
    static string STOCK_STATUS_AR = 'Agency Reserved';
    
    public CompanyDashboardWithOpp_V2()
    {
        init(); 
    }
    public void Init()
    { 
        List<Opportunity> sydney_Reserved_Unit_Opp_Lst = [SELECT Id FROM Opportunity WHERE (StageName =:STOCK_STATUS_AR)];
        Decimal Stock_Reserved=0;
        for(Opportunity opp : sydney_Reserved_Unit_Opp_Lst)
        {
            Stock_Reserved++;
        }
        
        SYD_Subtotal_Reserved_Unit = String.valueOf(Stock_Reserved); 
        system.debug('------SYD_Subtotal_Reserved_Unit----> '+SYD_Subtotal_Reserved_Unit);
    }
    
}

Let me know if this helps you.

Thank you
Ajay Dubedi
Aditya KamdiAditya Kamdi
I am not getting an error but the value is still being displayed as zero. I am sorry for the late response as I tried a couple of things by myself. is there any way I can check the value in the coding itself to check the value. 
To display on the page in a table  however I have simply written this piece of code 
 <td>{!SYD_Subtotal_Reserved_Unit}</td>
is there something wrong I am doing here 
Narender Singh(Nads)Narender Singh(Nads)
Hi Aditya,

Please try running this query in the query editor of your developer console and see if you are getting any records:
SELECT Id FROM Opportunity WHERE StageName = 'Agency Reserved'

If there are no records displayed then it means that there are no records with given stage name.
 
If yes then,

Try this code in your controller class and make sure your using this same class as your controller in your VF page:
public class CompanyDashboardWithOpp_V2 {
    
    public string SYD_Subtotal_Reserved_Unit{get;set;}
	static string STOCK_STATUS_AR = 'Agency Reserved';
	
    public CompanyDashboardWithOpp_V2(){
        List<Opportunity> sydney_Reserved_Unit_Opp_Lst=new List<Opportunity>();
        sydney_Reserved_Unit_Opp_Lst = [SELECT Id FROM Opportunity WHERE StageName =:STOCK_STATUS_AR];
    	SYD_Subtotal_Reserved_Unit=string.valueOf(sydney_Reserved_Unit_Opp_Lst.size());
        this.init();
    }

	public void Init(){ 
		system.debug('Fn called');
	}

}

Let me know if it helps,
Thanks!
 
Aditya KamdiAditya Kamdi
Hi Nads, 
Interestingly its not but I ran a report and it shows as 4 are agency reserved 
Narender Singh(Nads)Narender Singh(Nads)
Hi,
Can you please post the snapshot of that report you are running and the query editor results