I need to compare two dates in Months in Salesforce
Opportunity opp Target targ
If (Month(Opp.closeDate)== Month(targ.Target Date)
{
Add the target Id in Map
}
And the Id will be Queried in SOQL.This is a before Insert trigger on Opp.
Errors : Method does not exist or Incorrect signature :Void Month(Date) /Method does not exist or incorrect signature : void add(Id)from type map.
Can someone please guide me on how to compare date of Opp with Target.
Many Thanks
Update 1
trigger Updatetraget on Opportunity (after insert,after update) {
Map <Id,Opportunity> mappedopp = new Map <Id,Opportunity>(); {
for (Opportunity Opp : Trigger.new)
{
mappedopp.put(Opp.Monthly_Sales_Target__c,Opp);
}
List <Monthly_Sales_Target__c> msales = [SELECT Id, Name,Target_Month_and_Year__c FROM Monthly_Sales_Target__c where Id in :mappedopp.Keyset()];
for (Opportunity Opp : Trigger.new) {
for (Monthly_Sales_Target__c monthsales : msales)
{
if(Opp.StageName == 'Closed Won/Completed'&& Opp.CloseDate.Month()==monthsales.Target_Month_and_Year__c.month())
{
Opp.Monthly_Sales_Target__c = monthsales.Id;
update Opp;
}
}
}
} }