function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
plapla 

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

 

Best Answer chosen by Admin (Salesforce Developers) 
steve456steve456

Date.now().Month()

 

or

 

 

Date.Month()

All Answers

steve456steve456

Date.now().Month()

 

or

 

 

Date.Month()

This was selected as the best answer
plapla

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;

}

James LoghryJames Loghry

Integer currentMonth = Datetime.now().month();

 

Or Date.today().month();  either should give you the same result.

plapla

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;

}

James LoghryJames Loghry

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.

plapla

This one works. Thank you and have a nice day.

 

Effective_Date__c.month()

 

Paul