You need to sign in to do that
Don't have an account?
pla
Method does not exist in trigger
Hello,
What is the correct method to get the month of a given date in trigger? I used the method below but it throws me an error "Method does not exist" in trigger. Please help
Date.now.month
Thanks
Paul
Date.now().Month()
or
Date.Month()
All Answers
Date.now().Month()
or
Date.Month()
Thanks for your reply. But I still have the same error message using your suggested code. Any ideas?
for(Opportunity oppRec:trigger.new){
if (oppRec.Referral_Source__c == 'UMR'){
oppRec.Est_1st_Yr_Revenue__c = oppRec.Estimated_Lives__c * (12 - Date.now.Month(oppRec.Effective_Date__c)) * 0.92631331471426 * 61.1576598222772;
oppRec.Est_1st_Yr_Gross_Margin__c = oppRec.Estimated_Lives__c * (12 - Date.now.Month(oppRec.Effective_Date__c)) * 0.92631331471426 * 10.8437667634953;
}
Integer currentMonth = Datetime.now().month();
Or Date.today().month(); either should give you the same result.
I still got the same error message using your suggested code. Any advice is welcome. thanks
for(Opportunity oppRec:trigger.new){
if (oppRec.Referral_Source__c == 'UMR'){
oppRec.Est_1st_Yr_Revenue__c = oppRec.Estimated_Lives__c * (12 - Datetime.now().month(oppRec.Effective_Date__c)) * 0.92631331471426 * 61.1576598222772;
oppRec.Est_1st_Yr_Gross_Margin__c = oppRec.Estimated_Lives__c * (12 - Datetime.now().month(oppRec.Effective_Date__c)) * 0.92631331471426 * 10.8437667634953;
}
Sorry, pla, I missed your comment prior to mine by about a minute. :)
Looks like you're trying to get the month pertaining to oppRec.Effective_Date__c, and not the month associated with the current time.
So instead, you'll need to do something like oppRec.Effective_Date__c.month(); Note, that month does not take any parameters.
Hope that helps.
This one works. Thank you and have a nice day.
Effective_Date__c.month()
Paul