You need to sign in to do that
Don't have an account?
Aditya 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); } }
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);
}
}
Try this:
Let me know if it helps
Thanks
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
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
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:
Let me know if it helps,
Thanks!
Interestingly its not but I ran a report and it shows as 4 are agency reserved
Can you please post the snapshot of that report you are running and the query editor results