You need to sign in to do that
Don't have an account?
Customize existing apex class
We had an outside consultant create a customization for our company and part of the customization included a custom Apex class.
Line 17 of this customization is written as
for(OpportunityTeamMember ot:[select id,UserId,User.Name,Opportunity.OwnerId,Opportunity.Owner.Name from OpportunityTeamMember where OpportunityId=:lineItem.OpportunityId and User.Paid_on_Oppty_Sales_Credits__c=TRUE])
I need make an update that checks to see what the "Year" of the opporutnity close date is prior to running line 17 of this code.
I tried adding
IF(YEAR(Opporutnity.CloseDate) >= 2012) before line 17 but I get compile errors (because I know very little about APEX).
Error: Compile Error: Method does not exist or incorrect signature: YEAR(Schema.SObjectField)
What I would like to ulitmately do is add the following type of "if" statement to replace line 17 (the SOQL select statement is different depending on the outcome of the close date check).
IF(YEAR(Opporutnity.CloseDate) >= 2012)
for(OpportunityTeamMember ot:[select id,UserId,User.Name,Opportunity.OwnerId,Opportunity.Owner.Name from OpportunityTeamMember where OpportunityId=:lineItem.OpportunityId and User.Paid_on_Oppty_Sales_Credits__c=TRUE])
IF(YEAR(Opporutnity.CloseDate) < 2012)
for(OpportunityTeamMember ot:[select id,UserId,User.Name,Opportunity.OwnerId,Opportunity.Owner.Name from OpportunityTeamMember where OpportunityId=:lineItem.OpportunityId)
Can anybody recommend a solution to getting this added to our existing apex class. Thank you in advance for any advice.
I've attached the relevant portion of the existing APEX class below.
public with sharing class ProductSalesCredits { public List<SalesCreditListItem> salesCredits {get; private set;} public OpportunityLineItem lineItem {get; private set;} public Opportunity currencyOpp {get; private set;} public List<SelectOption> userOptions {get; private set;} public Integer deleteIndex {get;set;} public Double revenueForecast {get; private set;} public Double bookingAmount {get; private set;} public static final String TYPE_PRIMARY = 'Primary'; public static final String TYPE_ADDITIONAL = 'Additional'; private List<Sales_Credit__c> creditsToDelete = new List<Sales_Credit__c>(); private ProductSalesCredits(OpportunityLineItem lineItem, List<Sales_Credit__c> credits) { this.userOptions = new List<SelectOption>(); for(OpportunityTeamMember ot:[select id,UserId,User.Name,Opportunity.OwnerId,Opportunity.Owner.Name from OpportunityTeamMember where OpportunityId=:lineItem.OpportunityId and User.Paid_on_Oppty_Sales_Credits__c=TRUE]) this.userOptions.add(new SelectOption(ot.UserId,ot.User.Name)); Opportunity o=[select OwnerId,Owner.Name, CurrencyIsoCode from Opportunity where id=:lineItem.OpportunityId]; currencyOpp = o; this.userOptions.add(new SelectOption(o.OwnerId,o.Owner.Name)); this.lineItem = lineItem; this.salesCredits = new List<SalesCreditListItem>(); for (Integer i=0;i<credits.size();i++) { this.salesCredits.add(new SalesCreditListItem(credits[i],i)); }
Refer to this for Date methods
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm
So for eg
IF(Opporutnity.CloseDate.year() >= 2012)
All Answers
Refer to this for Date methods
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm
So for eg
IF(Opporutnity.CloseDate.year() >= 2012)
Thanks for the tip, it got me pointed in the right direction and I have everything working now.
Thanks!