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
CaisaCaisa 

Help: Error Message

Hello,

I am brand new to Apex.

I am getting the following error: Error: Compile Error: Expression cannot be a statement at line 47 column 7
o.Dynamic_Dates_TB__c is of type Checbox.

This is the code I wrote. What am I doing wrong?

trigger TBAutoClientInitiation on Opportunity (before update) 
{
public static Boolean IsWeekendDay(Date dateParam)
   {
      boolean result     = false;
      system.debug('dateParam = '+dateParam); 
      //Recover the day of the week
      Date startOfWeek   = dateParam.toStartOfWeek();
      system.debug('startOfWeek = '+startOfWeek);
      Integer dayOfWeek  = dateParam.day() - startOfWeek.day();
      system.debug('dayOfWeek = '+dayOfWeek);   
      result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
      system.debug('result = '+result); 
      return result;
   } 
   
public static Date AddBusinessDays(Date StartDate, integer BusinessDaysToAdd )
 {
      //Add or decrease in BusinessDaysToAdd days
      Date finalDate;
      if(StartDate != null )
       {
         finalDate = StartDate;
          system.debug('finaldate = '+finalDate);
          integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
          system.debug('direction = '+direction);
             while(BusinessDaysToAdd != 0)
            {
                finalDate = finalDate.AddDays(direction);
               system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);           
                 system.debug('finaldate = '+finalDate);
                if (!isWeekendDay(finalDate))
                {
                    BusinessDaysToAdd -= direction;
                    
               }
           }
        }  
       return finalDate;
  }
   {
  for(Opportunity o : Trigger.new)
    {
   
    if(o.Dynamic_Dates_TB__c==True)
     {
      o.TB_Kickoff_Call_w_Client_ED__c == AddBusinessDays(o.TB_Kickoff_Call_w_Client_SD__c,1);
      o.Data_Req_Start_Date__c == AddBusinessDays( o.TB_Kickoff_Call_w_Client_ED__c,18);
      }
     } 
    } 
}

 
Best Answer chosen by Caisa
sfdcMonkey.comsfdcMonkey.com
hi caisa 
try this 
trigger TBAutoClientInitiation on Opportunity (before update) 
{
public static Boolean IsWeekendDay(Date dateParam)
   {
      boolean result     = false;
      system.debug('dateParam = '+dateParam); 
      //Recover the day of the week
      Date startOfWeek   = dateParam.toStartOfWeek();
      system.debug('startOfWeek = '+startOfWeek);
      Integer dayOfWeek  = dateParam.day() - startOfWeek.day();
      system.debug('dayOfWeek = '+dayOfWeek);   
      result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
      system.debug('result = '+result); 
      return result;
   } 
   
public static Date AddBusinessDays(Date StartDate, integer BusinessDaysToAdd )
 {
      //Add or decrease in BusinessDaysToAdd days
      Date finalDate;
      if(StartDate != null )
       {
         finalDate = StartDate;
          system.debug('finaldate = '+finalDate);
          integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
          system.debug('direction = '+direction);
             while(BusinessDaysToAdd != 0)
            {
                finalDate = finalDate.AddDays(direction);
               system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);           
                 system.debug('finaldate = '+finalDate);
                if (!isWeekendDay(finalDate))
                {
                    BusinessDaysToAdd -= direction;
                    
               }
           }
        }  
       return finalDate;
  }
   {
  for(Opportunity o : Trigger.new)
    {
   
    if(o.Dynamic_Dates_TB__c==True)
     {
      o.TB_Kickoff_Call_w_Client_ED__c = AddBusinessDays(o.TB_Kickoff_Call_w_Client_SD__c,1);
      o.Data_Req_Start_Date__c = AddBusinessDays( o.TB_Kickoff_Call_w_Client_ED__c,18);
      }
     } 
    } 
}

 

All Answers

CaisaCaisa
Thank you this works!
sfdcMonkey.comsfdcMonkey.com
great..
If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
 
sfdcMonkey.comsfdcMonkey.com
hi caisa 
try this 
trigger TBAutoClientInitiation on Opportunity (before update) 
{
public static Boolean IsWeekendDay(Date dateParam)
   {
      boolean result     = false;
      system.debug('dateParam = '+dateParam); 
      //Recover the day of the week
      Date startOfWeek   = dateParam.toStartOfWeek();
      system.debug('startOfWeek = '+startOfWeek);
      Integer dayOfWeek  = dateParam.day() - startOfWeek.day();
      system.debug('dayOfWeek = '+dayOfWeek);   
      result = dayOfWeek == 0 || dayOfWeek == 6 ? true : false;
      system.debug('result = '+result); 
      return result;
   } 
   
public static Date AddBusinessDays(Date StartDate, integer BusinessDaysToAdd )
 {
      //Add or decrease in BusinessDaysToAdd days
      Date finalDate;
      if(StartDate != null )
       {
         finalDate = StartDate;
          system.debug('finaldate = '+finalDate);
          integer direction = BusinessDaysToAdd < 0 ? -1 : 1;
          system.debug('direction = '+direction);
             while(BusinessDaysToAdd != 0)
            {
                finalDate = finalDate.AddDays(direction);
               system.debug('BusinessDaysToAdd = '+BusinessDaysToAdd);           
                 system.debug('finaldate = '+finalDate);
                if (!isWeekendDay(finalDate))
                {
                    BusinessDaysToAdd -= direction;
                    
               }
           }
        }  
       return finalDate;
  }
   {
  for(Opportunity o : Trigger.new)
    {
   
    if(o.Dynamic_Dates_TB__c==True)
     {
      o.TB_Kickoff_Call_w_Client_ED__c = AddBusinessDays(o.TB_Kickoff_Call_w_Client_SD__c,1);
      o.Data_Req_Start_Date__c = AddBusinessDays( o.TB_Kickoff_Call_w_Client_ED__c,18);
      }
     } 
    } 
}

 
This was selected as the best answer
CaisaCaisa
Thanks Sonl - can you please help me with this question?
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000g1GxIAI