Notes
public class OpportunityUtility{
public static Opportunity getOpportunityById(Id OppID){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE Id =:OppID ];
}
public static List<Opportunity> getOpportunitiesByAccountId(Id acID){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE AccountId =:acID];
}
public static List<Opportunity> getOpportunitiesByLeadSource(String st){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE LeadSource =:st];
}
public static List<Opportunity> getOpportunitiesByStageName(String st){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE StageName =:st];
}
public static List<Opportunity> getOpportunitiesProbabilityLessThan(Integer pct){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE Probability <:pct];
}
public static List<Opportunity> getOpportunitiesProbabilityGreaterThan(Integer pct){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE Probability >:pct];
}
public static List<Opportunity> getOpportunitiesProbabilityEquals(Integer pct){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE Probability =:pct];
}
public static List<Opportunity> getOpportunitiesAmountLessThan(Decimal amt){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE Amount <:amt];
}
public static List<Opportunity> getOpportunitiesAmountGreaterThan(Decimal amt){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE Amount >:amt];
}
public static List<Opportunity> getOpportunitiesAmountEquals(Decimal amt){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE Amount =:amt];
}
public static List<Opportunity> getClosedOpportunities(){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE IsClosed = true];
}
public static List<Opportunity> getOpenedOpportunities(){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE IsClosed = false];
}
public static List<Opportunity> getOpportunitiesWithoutAccount(){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE AccountId = Null];
}
public static List<Opportunity> getOpportunitiesWithAccount(){
return [SELECT Name, AccountId, LeadSource, StageName, Probability, Amount, CloseDate FROM Opportunity WHERE AccountId != Null];
}
public static Integer getNumberOfOpportunities(){
return [SELECT Id FROM Opportunity].size();
}
public static Integer getNumberOfOpenedOpportunities(){
return [SELECT Id FROM Opportunity WHERE IsClosed = false].size();
}
public static Integer getNumberOfClosedOpportunities(){
return [SELECT Id FROM Opportunity WHERE IsClosed = true].size();
}
public static void create200OpportunitiesWithAccount(){
Account ac = new Account (Name = 'Test Account');
insert ac;
List<Opportunity> oppList = new List<Opportunity>();
for(Integer i=1; i<=200; i++){
oppList.add(new Opportunity(Name= 'Test Opportunity' + i, AccountId = ac.id, StageName='Negotiation/Review', CloseDate = date.today().adddays(15)));
}
insert oppList;
}
public static void create200OpportunitiesWithoutAccount(){
List<Opportunity> oppList = new List<Opportunity>();
for(Integer i=1; i<=200; i++){
oppList.add(new Opportunity(Name= 'Test Opportunity' + i, StageName='Negotiation/Review', CloseDate = date.today().adddays(15)));
}
insert oppList;
}
public static void createNOpportunitiesWithAccount(integer num){
Account ac = new Account (Name = 'Test Account');
insert ac;
List<Opportunity> oppList = new List<Opportunity>();
for(Integer i=1; i<=num; i++){
oppList.add(new Opportunity(Name= 'Test Opportunity' + i, AccountId = ac.id, StageName='Negotiation/Review', CloseDate = date.today().adddays(15)));
}
insert oppList;
}
public static void createNOpportunitiesWithoutAccount(integer num){
List<Opportunity> oppList = new List<Opportunity>();
for(Integer i=1; i<=num; i++){
oppList.add(new Opportunity(Name= 'Test Opportunity' + i, StageName='Negotiation/Review', CloseDate = date.today().adddays(15)));
}
insert oppList;
}
public static void deleteAllOpportunities(){
delete [SELECT Id FROM Opportunity];
}
public static void deleteAllOpportunitiesWithAccount(){
delete [SELECT Id FROM Opportunity WHERE AccountId != Null];
}
public static void deleteAllOpportunitiesWithoutAccount(){
delete [SELECT Id FROM Opportunity WHERE AccountId = Null];
}
public static void deleteTestOpportunities(){
delete [SELECT Id FROM Opportunity WHERE Name LIKE '%test%'];
}
}