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

problem to retrieve month value from date in trigger

trigger Behr_AmountOfMonths_US on THD_Sales__c (after insert,after update) {
    Set<Id> accset = new Set<Id>();
    Set<Id> thdset = new Set<Id>();
    List<THD_Sales__c> thdlst = new List<THD_Sales__c>();
    list<account> acclist = new list<account>();
    Map<Id,THD_Sales__c> thdmap = new Map<Id,THD_Sales__c>();
   map<Id,Double> AccountMap = new map <Id,Double>();

    for(THD_Sales__c thd : {
        if(thd.POS_Order_Type__c == 'Special Order' && MONTH(thd.Month_Year__c)=1) {
    for(AggregateResult q:[SELECT SFDC_Account_ID__c sfdcAccId,sum(Amount__c)tot FROM THD_Sales__c 
    where SFDC_Account_ID__c in :accset group by SFDC_Account_ID__c]) {
        Id sfdcId = (Id) q.get('sfdcAccId');
        Double dTotal = (decimal) q.get('tot'); 
        AccountMap.put(sfdcId, dTotal);

 Error: Compile Error: Method does not exist or incorrect signature: MONTH(Date) at line 11 column 56

if(thd.POS_Order_Type__c == 'Special Order' && MONTH(thd.Month_Year__c)=1)

Best Answer chosen by Admin (Salesforce Developers) 
Laxman RaoLaxman Rao

Use this:
if(thd.POS_Order_Type__c == 'Special Order' && thd.Month_Year__c.month() =1)


Refer this: