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
SFDC n12SFDC n12 

Soql query help needed

Hi,

I need help on the following requirement


1) i am having a custom object called as account exceptions__c where there are 2 picklist field called as ADR month__c(01 to 12)  and ADR YEAR__c(2014 to 2020)


2) there is a custom field Account__c lookup to account to this custom object 


when i enter the value for those fields, the number of account exceptions created under a specific account for which the adr month and year should be >13


for eg : if i enter 10/2013 it qualfies and if i enter 9/2013 it doesnt qualify since it is less than 13

also the number of records under this scenario is >3 a multi select picklist should be updated

i have written a trigger but its throwing a error


trigger AF_Approval on AccountExceptions__c (before insert , after insert )
{
    if (trigger.isInsert && trigger.isBefore)
    {
         List<Id> accId = new List<Id>();
         List<String> adrMonth = new List<String>();
    for(AccountExceptions__c spl:trigger.new)
    {
           accId.add(spl.Account__c);
           adrMonth.add(spl.ADR_Month__c);
   
    }

   List<AccountExceptions__c> lstAccExp = [Select Id,Account__c,ADR_Month__c,ADR_Years__c from AccountExceptions__c where Id =:accId ];


       if(lstAccExp.size()>3){
              for(AccountExceptions__c ac: lstAccExp){
              
           Date dt = Date.parse(ac.ADR_Years__c,ac.ADR_Month__c,'01');
           if(dt < System.today().addmonths(-13)){
            myobj.Executive_Committee_Approval__c='Yes';
            myobj.Executive_Approval_Reasons__c='Dealer Annual Limit Exceeded';
}
}

         
         }
         
         else{
         
         myobj.Executive_Committee_Approval__c='No';
         
         }



i am getting this complile error

Error: Compile Error: Variable does not exist: Date at line 65 column 22

 Date dt = Date.parse(ac.ADR_Years__c,ac.ADR_Month__c,'01');

ADR_Years__c,ADR_Month__c are picklist values should i not use a date function for this


Please help me

Thanks in Advance

 
Balaji BondarBalaji Bondar
replace below code
String dateStr = ac.ADR_Month__c +'/01/'+ac.ADR_Years__c;
Date dt = Date.parse(dateStr);
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.