You need to sign in to do that
Don't have an account?
Hariharan M 18
display sum of amount of opportunities in a stage (stage name as parameter-> you can take any one stage name) can anyone help on this?
display sum of amount of opportunities in a stage (stage name as parameter-> you can take any one stage name)
can anyone help on this?
can anyone help on this?
Try below Code Please Mark It As Best Asnwer If It Helps
Thank You!
All Answers
Hey hariharan,
Can you kindly elaborate the requirement. Where exactly you want to update the amout amout ? On Account Object?
Thanks,
Priya Ranjan
stage name = closed won
Amount = total amount of opportunities in the stage ' closed won'
as highlighted in the below image if am entering stage name as closed won the the total of amounts highlighted in blue should be calculated,
i tried as below
public class OppurtunityPracticeClass {
public static void practiceFunction()
{
decimal diffStageName ='Closed Won';
List<AggregateResult> opportunityList = [
SELECT
COUNT(ID) CountofId,StageName, Amount
FROM
Opportunity
WHERE
StageName =: diffStageName
GROUP BY StageName
];
for (AggregateResult opp:opportunityList)
{
system.debug(opp.get('StageName'));
system.debug(opp.get('CountofID'));
system.debug(opp.get('Amount'));
}
}
}
but am not clear how to calculate the total amount
Try Below Trigger Please Mark It As Best Asnwer If It Helps
Thank You!
I need the code similar to sample i have pasted above,
i need it in SOQL query inside a class.. Not in trigger,,
now i have rewrote the code its working fine but am not able to group it by stage name,
try below code:
Public class OppurtunityPracticeClass{
public static void practiceFunction()
{
decimal sumOfAmount=0;
string diffStageName ='Closed Won';
List<Opportunity> opportunityList = [
SELECT
Amount,StageName
FROM
Opportunity
WHERE
StageName =: diffStageName
//GROUP BY StageName
];
for (Opportunity opp:opportunityList)
{
sumOfAmount += opp.Amount;
system.debug(opp.get('StageName'));
//system.debug(opp.Amount);
}
system.debug(sumOfAmount);
}
}
in the output, i need the stage name - closed won to be displayed only once,
but if try to group by in soql its throws error in code.
let me know if you could fix it
Try below Code Please Mark It As Best Asnwer If It Helps
Thank You!