• Caisa
  • NEWBIE
  • 50 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 17
    Replies
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);
      }
     } 
    } 
}

 
  • September 02, 2016
  • Like
  • 0
Hello,

When I am executing my Apex tests, I get this error - can someone please help with this?

Thank you!

User-added image
  • August 05, 2016
  • Like
  • 0
Can someone please help solve this NullPointer Exception:

Error:Apex trigger TruBidCompletion caused an unexpected exception, contact your administrator: TruBidCompletion: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TruBidCompletion: line 31, column 1

trigger TruBidCompletion 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 = 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 the user selects Round 1 as the Number of TruBid Rounds */
    if(o.Number_of_Rounds_in_TruBid__c=='Round 1')
    {
    /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_1_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays( o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
    }
   
  • August 05, 2016
  • Like
  • 0
Can you please help me write an Apex Test Class for this:

public class Opp_Ext {
    private ApexPages.StandardController stdController;
    public String redirectUrl {public get; private set;}
    public Boolean shouldRedirect {public get; private set;}

    public Opp_Ext(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        shouldRedirect = false;
    }

    public PageReference doStuffAndRedirect() {
        shouldRedirect = true;
        redirectUrl = stdController.view().getUrl();
        return null;
    }
}
  • August 05, 2016
  • Like
  • 0
I am brand new to Apex Testing. Can someone please help me write the Apex Test Class for this code.
Also, can you please tell me where should I execute the Test Class that you helped me with? 
trigger TGAuditFinalReport on Opportunity (before update)
{
 
  for(Opportunity o : Trigger.new)
    {
    o.FR_Deliver_Report_to_PBM_AM_End_Date__c =o.FR_Deliver_Report_to_PBM_AM_Start_Date__c;
        
    }
   
}


 
  • August 05, 2016
  • Like
  • 0
Hello,

I am brand new to Apex Testing and have a deadline this week. Can someone please tell me how to write the Apex Test for this:

trigger TruBidCompletion 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 = 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 the user selects Round 1 as the Number of TruBid Rounds */
    if(o.Number_of_Rounds_in_TruBid__c=='Round 1')
    {
    /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_1_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays( o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
    }
   
    
    else if 
    /* If the user selects Round 2 as the Number of TruBid Rounds */
    (o.Number_of_Rounds_in_TruBid__c=='Round 2')
    {
     /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_2_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays(o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
   }
   
   else if 
   /* If the user selects Round 3 as the Number of TruBid Rounds */
    (o.Number_of_Rounds_in_TruBid__c=='Round 3')
    {
     /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_3_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays(o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
   }
   
}
   
 } 
  • August 05, 2016
  • Like
  • 0
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);
      }
     } 
    } 
}

 
  • September 02, 2016
  • Like
  • 0
Can someone please help solve this NullPointer Exception:

Error:Apex trigger TruBidCompletion caused an unexpected exception, contact your administrator: TruBidCompletion: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TruBidCompletion: line 31, column 1

trigger TruBidCompletion 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 = 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 the user selects Round 1 as the Number of TruBid Rounds */
    if(o.Number_of_Rounds_in_TruBid__c=='Round 1')
    {
    /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_1_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays( o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
    }
   
  • August 05, 2016
  • Like
  • 0
Can you please help me write an Apex Test Class for this:

public class Opp_Ext {
    private ApexPages.StandardController stdController;
    public String redirectUrl {public get; private set;}
    public Boolean shouldRedirect {public get; private set;}

    public Opp_Ext(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        shouldRedirect = false;
    }

    public PageReference doStuffAndRedirect() {
        shouldRedirect = true;
        redirectUrl = stdController.view().getUrl();
        return null;
    }
}
  • August 05, 2016
  • Like
  • 0
I am brand new to Apex Testing. Can someone please help me write the Apex Test Class for this code.
Also, can you please tell me where should I execute the Test Class that you helped me with? 
trigger TGAuditFinalReport on Opportunity (before update)
{
 
  for(Opportunity o : Trigger.new)
    {
    o.FR_Deliver_Report_to_PBM_AM_End_Date__c =o.FR_Deliver_Report_to_PBM_AM_Start_Date__c;
        
    }
   
}


 
  • August 05, 2016
  • Like
  • 0
Hello,

I am brand new to Apex Testing and have a deadline this week. Can someone please tell me how to write the Apex Test for this:

trigger TruBidCompletion 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 = 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 the user selects Round 1 as the Number of TruBid Rounds */
    if(o.Number_of_Rounds_in_TruBid__c=='Round 1')
    {
    /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_1_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays( o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
    }
   
    
    else if 
    /* If the user selects Round 2 as the Number of TruBid Rounds */
    (o.Number_of_Rounds_in_TruBid__c=='Round 2')
    {
     /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_2_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays(o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
   }
   
   else if 
   /* If the user selects Round 3 as the Number of TruBid Rounds */
    (o.Number_of_Rounds_in_TruBid__c=='Round 3')
    {
     /* Call the AddBusinessDays method called above to add 'x' days */
    o.Contract_Draft_Requested_Start_Date__c=o.Rd_3_Results_Review_End_Date__c;
    o.Contract_Draft_Requested_End_Date__c=AddBusinessDays(o.Contract_Draft_Requested_Start_Date__c,1);
    o.Award_Start_Date__c=o.Contract_Draft_Requested_End_Date__c;
    o.Award_End_Date__c=AddBusinessDays(o.Award_Start_Date__c,15);
    o.TB_Draft_Received_Start_Date__c= o.Award_End_Date__c;
    o.TB_Draft_Received_End_Date__c=o.Award_End_Date__c;
    o.TB_Edits_in_Progress_Start_Date__c=o.TB_Draft_Received_End_Date__c;
    o.TB_Edits_in_Progress_End_Date__c=AddBusinessDays(o.TB_Edits_in_Progress_Start_Date__c,47);
    o.TB_Contract_Signed_Start_Date__c=o.TB_Edits_in_Progress_End_Date__c;
    o.TB_Contract_Signed_End_Date__c=AddBusinessDays(o.TB_Contract_Signed_Start_Date__c,1);
   }
   
}
   
 } 
  • August 05, 2016
  • Like
  • 0