• Chrisludovice
  • NEWBIE
  • 44 Points
  • Member since 2019
  • Salesforce Consultant

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 10
    Replies

Hi all, 

I have a question regarding the DATETIMEVALUE function. I'm creating a task each time a projects starts, and i would like to set the reminder at 09:30:00. So the date is based on a field, but the time should be fixed. I have tried multiple formulas, currently i have the following: 


DATETIMEVALUE(Customfield__c  & " " & 09:30:00) 

However, i receive an error that i miss a bracket: 

The formula expression is invalid: Syntax error. Missing ')'

Anyone any ideas? 

Kind regards, Loran

 

Hi Experts,

I am creating a custom button and when clicked, it generates the PDF and saves it in attachment but am encountering an error:
Too many nested getContent calls

Below is my Apex extension for the VF:

public class attachPDFToAccount {
    
    private final Account a; //Account object
    public String pdfContent = '<h1>Lorem Ipsum</h1><h4>"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."</h4><h5>"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."</h5>';
    
     //constructor
    public attachPDFToAccount(ApexPages.StandardController standardPageController) {
        a = (Account)standardPageController.getRecord(); //instantiate the Account object for the current record
    } 
    
    //method called from the Visualforce's action attribute
    public PageReference attachPDF() {
        
        //generate and attach the PDF document
        PageReference pdfPage = new PageReference('/apex/GenerateSOA'); //create a page reference to our pdfDemo Visualforce page, which was created from the post https://interactiveties.com/blog/2015/render-visualforce-pdf.php
        Blob pdfBlob; //create a blob for the PDF content
        if (!Test.isRunningTest()) { //if we are not in testing context
            pdfBlob = pdfPage.getContent(); //generate the pdf blob
        } else { //otherwise, we are in testing context and getContent() gets funky so create the blob manually
        pdfBlob = Blob.valueOf(pdfContent);
        }
        Attachment attach = new Attachment(parentId = a.Id, Name = 'accSOA -' + DateTime.now().formatLong() + '.pdf', body = pdfBlob); //create the attachment object
        insert attach; //insert the attachment
        
        //redirect the user
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); //we want to redirect the User back to the Account detail page
        pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
        return pageWhereWeWantToGo; //send the User on their way
    }

}

Here's my VF:

<apex:page action="{!attachPDF}" extensions="attachPDFToAccount" standardController="Account">
<!--
    Created by: Chris Ludovice
    Last Update: 10 May 2019 by Chris Ludovice
    
    Notes:
        - Visualforce page for creating a PDF file and attaching to Account
-->
    <apex:pageMessages ></apex:pageMessages><!-- included for display of errors should they occur -->
    <apex:detail inlineEdit="true" relatedList="true"></apex:detail> <!-- included so Account detail information is visible when errors occur -->
</apex:page>


Thanks.
Regards,
Chris L.
Hi,

I am only getting 36% of my test class. Can you help me on this one?

Thanks.

SCHEDULED APEX:

/**
*author Chris Ludovice
*@date  4.15.2019
*description Schedulable apex class(invokable) responsible for missed invoices email alert.
@revision(s)
 */

global class SS_EscalationAlertsMIR implements Schedulable {
    
       // initialize email related variables
       public String htmlSP = '';
       public String htmlMgr = '';
       public String htmlClevel = '';
       public String htmlSend = '';
       public String subjectSP = 'First Escalation: Accounts with Missed Invoices';
       public String subjectMgr = 'Second Escalation: Accounts with Missed Invoices'; 
       public String subjectClevel = 'Third Escalation: Accounts with Missed Invoices'; 
       public String subjectSend = ''; 
       public String htmlAppendSP = '----------First Escalation: Accounts with Missed Invoices----------</br>';
       public String htmlAppendMgr = '----------Second Escalation: Accounts with Missed Invoices----------</br>';
       public String htmlMgr15 = '';
       public String htmlMgr30 = '';
       public String htmlC15 = '';
       public String htmlC30 = ''; 
    
       public String dateFormatString = 'yyyy-MM-dd';
        
       public String[] toAddressesSP = new List<String>(); // holds SP's email... 
       public String[] toAddressesMgr = new List<String>(); // holds Manager's email...   
       public String[] toAddressesClevel = new List<String>(); // holds Clevel's email...  
       public String[] toAddresses = new List<String>(); // holds the actual email recipient..
    
       // initialize sp <td> variables...
       public Date dSP = system.today();
       public Datetime dtSP = system.now();
       public String dateStringSP = '';
       public Set<String> uniqueSP = new Set<String>();
    
          // initialize mgr <td> variables...
       public Decimal s = 0.00;
       public Date dMgr = system.today();
       public Datetime dtMgr = system.now();
       public String dateStringMgr = '';
       public Set<String> uniqueMgr = new Set<String>();
    
       // initialize clevel <td> variables...
       public Decimal m = 0.00;
       Date dClevel = system.today();
       Datetime dtClevel = system.now();
       String dateStringClevel = '';
   
    global void execute(SchedulableContext ctx) {
        
         // remove Name='Report-Scheduler-Missed-Invoice after testing...
        
        // render sp missed invoice (>=15days overdue) and < 30?
         List<Account> spList = [SELECT Id, Sales_Rep__r.User_account__r.Email, Name,Latest_Service_End_Date__c,Days_Overdue_Missed_Invoice__c,Sales_Rep__r.Name FROM Account
            WHERE Name='Report-Scheduler-Missed-Invoice' AND (Days_Overdue_Missed_Invoice__c >= 15 AND Days_Overdue_Missed_Invoice__c < 30) AND Current_Contract_Status__c = 'Active'];        
       
       // render mgr missed invoice (>=30days overdue) and < 45?
         List<Account> mgrList = [SELECT Id, Sales_Rep__r.User_account__r.Manager.Email, Name,Latest_Service_End_Date__c,Days_Overdue_Missed_Invoice__c,Sales_Rep__r.Name FROM Account
            WHERE Name='Report-Scheduler-Missed-Invoice' AND (Days_Overdue_Missed_Invoice__c >= 30 AND Days_Overdue_Missed_Invoice__c < 45) AND Current_Contract_Status__c = 'Active'];      
 
       // render clevel missed invoice (>=45days overdue)
         List<Account> cList = [SELECT Id, Name,Latest_Service_End_Date__c,Days_Overdue_Missed_Invoice__c,Sales_Rep__r.Name FROM Account
            WHERE Name='Report-Scheduler-Missed-Invoice' AND Days_Overdue_Missed_Invoice__c >= 45 AND Current_Contract_Status__c = 'Active'];  
      
       // initialize html table variables for each email body...
                
      if(spList.size()>0){   // check if SP missed invoice SOQL has returned row(s)..  
      
       htmlSP = '<p>You are receiving this email as one of your accounts may not have billed at least 15 days after its expected subscription end date. Please raise corresponding subscription/membership opportunity.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+spList.size()+'</br><i>As of:&nbsp;'+datetime.now().format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';          
      
       for(Account accSP:spList)
        {
            toAddressesSP.Add(accSP.Sales_Rep__r.User_account__r.Email); // add emails in SP array..  
            dSP = accSP.Latest_Service_End_Date__c;
            Datetime dtSP = Datetime.newInstance(dSP.year(), dSP.month(),dSP.day());
            dateStringSP = dtSP.format(dateFormatString);
            htmlSP += '<tr><td><a target="_blank" href="'+system.label.Salesforce_Instance_URL+accSP.Id+'">'+ accSP.Name + '</a></td><td>'+accSP.Sales_Rep__r.Name+'</td><td>' + dateStringSP + '</td><td>'+accSP.Days_Overdue_Missed_Invoice__c+'</td></tr>';

        }      
             //close table...
            htmlSP += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
            system.debug(htmlSP);  
            
            // get unique SP emails in the array...
            uniqueSP.addAll(toAddressesSP);
            toAddresses.AddAll(uniqueSP);
          
              subjectSend = subjectSP;
            htmlSend = htmlSP;
              SS_EmailUtility.SendEmail(htmlSend, toAddresses, subjectSend); 
          
      } // end of IF for SP...
        
      if(mgrList.size()>0){   // check if Mgr missed invoice SOQL has returned row(s)..  
      
       htmlMgr = '<p>Being the manager of the identified account managers, listed accounts have not been billed for at least 30 days.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+mgrList.size()+'</br><i>As of:&nbsp;'+datetime.now().format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';  
       htmlMgr15 = '<p>You are receiving this email as one of your accounts may not have billed at least 15 days after its expected subscription end date. Please raise corresponding subscription/membership opportunity.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+mgrList.size()+'</br><i>As of:&nbsp;'+datetime.now().addDays(-15).format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';  
          
       for(Account accMgr:mgrList)
        {
       
            toAddressesMgr.Add(accMgr.Sales_Rep__r.User_account__r.Manager.Email); // add emails in Mgr array..
            dMgr = accMgr.Latest_Service_End_Date__c;
            dtMgr = Datetime.newInstance(dMgr.year(), dMgr.month(),dMgr.day());
            dateStringMgr= dtMgr.format(dateFormatString);
            s = accMgr.Days_Overdue_Missed_Invoice__c-15;
            htmlMgr += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accMgr.Id+'">'+accMgr.Name + '</a></td><td>'+accMgr.Sales_Rep__r.Name+'</td><td>' + dateStringMgr + '</td><td>'+accMgr.Days_Overdue_Missed_Invoice__c+'</td></tr>';
            htmlMgr15 += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accMgr.Id+'">'+accMgr.Name + '</a></td><td>'+accMgr.Sales_Rep__r.Name+'</td><td>' + Date.valueOf(dateStringMgr).format() + '</td><td>'+s+'</td></tr>';

            
        } 
             //close table...
            htmlMgr += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
            htmlMgr15 += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
              htmlAppendSP += htmlMgr15;
            htmlMgr += htmlAppendSP;    
            system.debug(htmlMgr);              
             
            // get unique Mgr emails in the array...           
            uniqueMgr.addAll(toAddressesMgr);
            toAddresses.AddAll(uniqueMgr);
          
              subjectSP = 'Second Escalation: Accounts with Missed Invoices';
              subjectSend = subjectMgr;
            htmlSend = htmlMgr;
              SS_EmailUtility.SendEmail(htmlSend, toAddresses, subjectSend); 
          
      } // end of IF for Mgr...
    
      if(cList.size()>0){   // check if Clevel missed invoice SOQL has returned row(s)..  
      
       htmlClevel = '<p>Escalating to Senior Executive Group as accounts listed below have not been billed for at least 45 days.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+cList.size()+'</br><i>As of:&nbsp;'+datetime.now().format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';          
       htmlC30 = '<p>Being the manager of the identified account managers, listed accounts have not been billed for at least 30 days.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+cList.size()+'</br><i>As of:&nbsp;'+datetime.now().addDays(-15).format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';  
       htmlC15 = '<p>You are receiving this email as one of your accounts may not have billed at least 15 days after its expected subscription end date. Please raise corresponding subscription/membership opportunity.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+cList.size()+'</br><i>As of:&nbsp;'+datetime.now().addDays(-30).format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';    
          
       for(Account accClevel:cList)
        {
       
            dClevel = accClevel.Latest_Service_End_Date__c;
            dtClevel = Datetime.newInstance(dClevel.year(), dClevel.month(),dClevel.day());
            dateStringClevel= dtClevel.format(dateFormatString);
            s = accClevel.Days_Overdue_Missed_Invoice__c-30;
            m = accClevel.Days_Overdue_Missed_Invoice__c-15;
            htmlClevel += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accClevel.Id+'">'+accClevel.Name + '</a></td><td>'+accClevel.Sales_Rep__r.Name+'</td><td>' + dateStringClevel + '</td><td>'+accClevel.Days_Overdue_Missed_Invoice__c+'</td></tr>';

            htmlC15 += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accClevel.Id+'">'+accClevel.Name + '</a></td><td>'+accClevel.Sales_Rep__r.Name+'</td><td>' + Date.valueOf(dateStringClevel).format() + '</td><td>'+s+'</td></tr>';
            htmlC30 += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accClevel.Id+'">'+accClevel.Name + '</a></td><td>'+accClevel.Sales_Rep__r.Name+'</td><td>' + Date.valueOf(dateStringClevel).format() + '</td><td>'+m+'</td></tr>';
            
        } 
             
      // Select all user emails from Clevel PG...
      Group grp = [SELECT Id FROM Group Where DeveloperName ='Clevel_Users']; // fetch PG Id
      List<GroupMember> grpm = [SELECT UserOrGroupId FROM GroupMember Where GroupId =:grp.Id]; // fetch Group Users Id...
      Set<Id> grpmIds = new Set<Id>();  
      for(GroupMember grpmSet :grpm){
          grpmIds.add(grpmSet.UserOrGroupId);
            }
      List<User> cUsers = [SELECT Email FROM User Where Id=:grpmIds]; // fetch cleveluser's email.
        for(User cu: cUsers)  {
         toAddressesClevel.Add(cu.Email);  // add emails in clevel array..
         system.debug('Clevel Emails: '+toAddressesClevel); 
        }          
          
     //close table...
     htmlClevel += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
     system.debug(htmlClevel);              
     toAddresses = toAddressesClevel;               
     subjectClevel = 'Third Escalation: Accounts with Missed Invoices';
     subjectSend = subjectClevel;
          
     htmlC15 += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
     htmlC30 += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';     
     htmlAppendSP += htmlC15;
     htmlAppendMgr += htmlC30;
     htmlAppendMgr += htmlAppendSP;     
     htmlClevel += htmlAppendMgr;
    
     htmlSend = htmlClevel;
     SS_EmailUtility.SendEmail(htmlSend, toAddresses, subjectSend); 
          
      } // end of IF for Clevel...
  
               
     } // end of execute constructor...
    
} // end of main class..

***********************************************************************

TEST CLASS:

@isTest 
private class SS_EscalationAlertsMIRTest {
    
     // Dummy CRON expression: midnight on May 1.
    // Because this is a test, job executes
   // immediately after Test.stopTest().
   
   public static String CRON_EXP = '0 0 0 1 5 ? 2019';
    
    static testmethod void testScheduledJob() { 
                
       // Create test Account record
        Account accs = new Account();
        Date servDate = Date.today().addDays(-45);
        accs.Name = 'Test';
        accs.Latest_Service_End_Date__c = servDate;
        
        // select profile.....
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];     
              
        User ManagerToCreate = new User(); //Create a manager user
        ManagerToCreate.Email='ManagerUserA@testorganise.com';
        ManagerToCreate.Alias = 'standard';
        ManagerToCreate.EmailEncodingKey='UTF-8';
        ManagerToCreate.LastName='Manager Test';
        ManagerToCreate.LanguageLocaleKey='en_US';
        ManagerToCreate.LocaleSidKey='en_US';
        ManagerToCreate.TimeZoneSidKey='America/Los_Angeles';
        ManagerToCreate.UserName='ManagerUserA@testorganise.com';
        ManagerToCreate.ProfileId = p.Id;
        insert ManagerToCreate;

        User userToCreate = new User(); // Create an Employee
        userToCreate.Email='UserA@testorganise.com';
        userToCreate.Alias = 'standard';
        userToCreate.EmailEncodingKey='UTF-8';
        userToCreate.LastName='User Test';
        userToCreate.LanguageLocaleKey='en_US';
        userToCreate.LocaleSidKey='en_US';
        userToCreate.TimeZoneSidKey='America/Los_Angeles';
        userToCreate.UserName='UserA@testorganise.com';
        userToCreate.ManagerId = ManagerToCreate.Id;  // Assign Manager to an Employee
        userToCreate.ProfileId = p.Id;
        insert userToCreate;
        
                                                           
       Test.startTest();
        
       system.runAs(userToCreate){
        
       // Setup shipserv person test data
       ShipServ_People__c sp = new ShipServ_People__c(Name='last', User_account__c=userToCreate.Id);
       insert sp;
       system.debug('id of user:'+sp.User_account__c+sp.User_account__c); 
            
        accs.Sales_Rep__c = sp.Id;   
        insert accs;  
        
        // Get the accounts that were just inserted       
        list<Account> uRetrieve = [select id from account]; //retrieve the record
        integer acc = uRetrieve.size();
        system.assertEquals(1,acc);//Test that the record is inserted
                       
        //Create public group...
        Group gp = new Group(Name = 'Test', DeveloperName='test');
        insert gp;
                      
        // Create group member...
        GroupMember gpm = new GroupMember();
        gpm.GroupId = gp.Id;
        gpm.UserOrGroupId = userToCreate.Id;
        insert(gpm);        
        system.debug('group member inserted:'+gpm.id);
           
        // Get the group member that's just inserted 
        list<GroupMember>gpmRetrieve = [select id from GroupMember where Group.DeveloperName='test']; //retrieve the record
        integer gpm2 = gpmRetrieve.size();
        system.assertEquals(1,gpm2);//Test that the record is inserted
           
       Id[] fixedSearchResults = new Id[2];
       fixedSearchResults[0] = accs.Id;
           
           
       // create an instance of the class... 
       SS_EscalationAlertsMIR mir = new SS_EscalationAlertsMIR();
       mir.htmlSP += 'test'+acc+datetime.now().format();
       mir.execute(null);    
          
       } // end of system.runAs...
                    
          // Schedule the test job
        String jobId = System.schedule('ScheduledApexTest',
            CRON_EXP, 
            new SS_EscalationAlertsMIR());
        
       // SS_EmailUtility.SendEmail('Unit Test X', new List<String>{'test@test.com'});
        
        Test.stopTest(); 

    }
}
Hi Experts,

I am creating a custom button and when clicked, it generates the PDF and saves it in attachment but am encountering an error:
Too many nested getContent calls

Below is my Apex extension for the VF:

public class attachPDFToAccount {
    
    private final Account a; //Account object
    public String pdfContent = '<h1>Lorem Ipsum</h1><h4>"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."</h4><h5>"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."</h5>';
    
     //constructor
    public attachPDFToAccount(ApexPages.StandardController standardPageController) {
        a = (Account)standardPageController.getRecord(); //instantiate the Account object for the current record
    } 
    
    //method called from the Visualforce's action attribute
    public PageReference attachPDF() {
        
        //generate and attach the PDF document
        PageReference pdfPage = new PageReference('/apex/GenerateSOA'); //create a page reference to our pdfDemo Visualforce page, which was created from the post https://interactiveties.com/blog/2015/render-visualforce-pdf.php
        Blob pdfBlob; //create a blob for the PDF content
        if (!Test.isRunningTest()) { //if we are not in testing context
            pdfBlob = pdfPage.getContent(); //generate the pdf blob
        } else { //otherwise, we are in testing context and getContent() gets funky so create the blob manually
        pdfBlob = Blob.valueOf(pdfContent);
        }
        Attachment attach = new Attachment(parentId = a.Id, Name = 'accSOA -' + DateTime.now().formatLong() + '.pdf', body = pdfBlob); //create the attachment object
        insert attach; //insert the attachment
        
        //redirect the user
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); //we want to redirect the User back to the Account detail page
        pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
        return pageWhereWeWantToGo; //send the User on their way
    }

}

Here's my VF:

<apex:page action="{!attachPDF}" extensions="attachPDFToAccount" standardController="Account">
<!--
    Created by: Chris Ludovice
    Last Update: 10 May 2019 by Chris Ludovice
    
    Notes:
        - Visualforce page for creating a PDF file and attaching to Account
-->
    <apex:pageMessages ></apex:pageMessages><!-- included for display of errors should they occur -->
    <apex:detail inlineEdit="true" relatedList="true"></apex:detail> <!-- included so Account detail information is visible when errors occur -->
</apex:page>


Thanks.
Regards,
Chris L.
Hello, 

Can someone tell me if there is Salesforce Connector  for MuleSoft that is compatible with vesrion 45.0 of Salesforce.

Thank you.
Hi Team,

Please let me know if there is any way to turn off system validations.


Thanks.
Hello All,

I have created web serivce for Email-to-case and enable "Save Email-to-Case attachments as Salesforce Files" but Ticket not created with attachment . 
Hi,

I am only getting 36% of my test class. Can you help me on this one?

Thanks.

SCHEDULED APEX:

/**
*author Chris Ludovice
*@date  4.15.2019
*description Schedulable apex class(invokable) responsible for missed invoices email alert.
@revision(s)
 */

global class SS_EscalationAlertsMIR implements Schedulable {
    
       // initialize email related variables
       public String htmlSP = '';
       public String htmlMgr = '';
       public String htmlClevel = '';
       public String htmlSend = '';
       public String subjectSP = 'First Escalation: Accounts with Missed Invoices';
       public String subjectMgr = 'Second Escalation: Accounts with Missed Invoices'; 
       public String subjectClevel = 'Third Escalation: Accounts with Missed Invoices'; 
       public String subjectSend = ''; 
       public String htmlAppendSP = '----------First Escalation: Accounts with Missed Invoices----------</br>';
       public String htmlAppendMgr = '----------Second Escalation: Accounts with Missed Invoices----------</br>';
       public String htmlMgr15 = '';
       public String htmlMgr30 = '';
       public String htmlC15 = '';
       public String htmlC30 = ''; 
    
       public String dateFormatString = 'yyyy-MM-dd';
        
       public String[] toAddressesSP = new List<String>(); // holds SP's email... 
       public String[] toAddressesMgr = new List<String>(); // holds Manager's email...   
       public String[] toAddressesClevel = new List<String>(); // holds Clevel's email...  
       public String[] toAddresses = new List<String>(); // holds the actual email recipient..
    
       // initialize sp <td> variables...
       public Date dSP = system.today();
       public Datetime dtSP = system.now();
       public String dateStringSP = '';
       public Set<String> uniqueSP = new Set<String>();
    
          // initialize mgr <td> variables...
       public Decimal s = 0.00;
       public Date dMgr = system.today();
       public Datetime dtMgr = system.now();
       public String dateStringMgr = '';
       public Set<String> uniqueMgr = new Set<String>();
    
       // initialize clevel <td> variables...
       public Decimal m = 0.00;
       Date dClevel = system.today();
       Datetime dtClevel = system.now();
       String dateStringClevel = '';
   
    global void execute(SchedulableContext ctx) {
        
         // remove Name='Report-Scheduler-Missed-Invoice after testing...
        
        // render sp missed invoice (>=15days overdue) and < 30?
         List<Account> spList = [SELECT Id, Sales_Rep__r.User_account__r.Email, Name,Latest_Service_End_Date__c,Days_Overdue_Missed_Invoice__c,Sales_Rep__r.Name FROM Account
            WHERE Name='Report-Scheduler-Missed-Invoice' AND (Days_Overdue_Missed_Invoice__c >= 15 AND Days_Overdue_Missed_Invoice__c < 30) AND Current_Contract_Status__c = 'Active'];        
       
       // render mgr missed invoice (>=30days overdue) and < 45?
         List<Account> mgrList = [SELECT Id, Sales_Rep__r.User_account__r.Manager.Email, Name,Latest_Service_End_Date__c,Days_Overdue_Missed_Invoice__c,Sales_Rep__r.Name FROM Account
            WHERE Name='Report-Scheduler-Missed-Invoice' AND (Days_Overdue_Missed_Invoice__c >= 30 AND Days_Overdue_Missed_Invoice__c < 45) AND Current_Contract_Status__c = 'Active'];      
 
       // render clevel missed invoice (>=45days overdue)
         List<Account> cList = [SELECT Id, Name,Latest_Service_End_Date__c,Days_Overdue_Missed_Invoice__c,Sales_Rep__r.Name FROM Account
            WHERE Name='Report-Scheduler-Missed-Invoice' AND Days_Overdue_Missed_Invoice__c >= 45 AND Current_Contract_Status__c = 'Active'];  
      
       // initialize html table variables for each email body...
                
      if(spList.size()>0){   // check if SP missed invoice SOQL has returned row(s)..  
      
       htmlSP = '<p>You are receiving this email as one of your accounts may not have billed at least 15 days after its expected subscription end date. Please raise corresponding subscription/membership opportunity.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+spList.size()+'</br><i>As of:&nbsp;'+datetime.now().format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';          
      
       for(Account accSP:spList)
        {
            toAddressesSP.Add(accSP.Sales_Rep__r.User_account__r.Email); // add emails in SP array..  
            dSP = accSP.Latest_Service_End_Date__c;
            Datetime dtSP = Datetime.newInstance(dSP.year(), dSP.month(),dSP.day());
            dateStringSP = dtSP.format(dateFormatString);
            htmlSP += '<tr><td><a target="_blank" href="'+system.label.Salesforce_Instance_URL+accSP.Id+'">'+ accSP.Name + '</a></td><td>'+accSP.Sales_Rep__r.Name+'</td><td>' + dateStringSP + '</td><td>'+accSP.Days_Overdue_Missed_Invoice__c+'</td></tr>';

        }      
             //close table...
            htmlSP += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
            system.debug(htmlSP);  
            
            // get unique SP emails in the array...
            uniqueSP.addAll(toAddressesSP);
            toAddresses.AddAll(uniqueSP);
          
              subjectSend = subjectSP;
            htmlSend = htmlSP;
              SS_EmailUtility.SendEmail(htmlSend, toAddresses, subjectSend); 
          
      } // end of IF for SP...
        
      if(mgrList.size()>0){   // check if Mgr missed invoice SOQL has returned row(s)..  
      
       htmlMgr = '<p>Being the manager of the identified account managers, listed accounts have not been billed for at least 30 days.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+mgrList.size()+'</br><i>As of:&nbsp;'+datetime.now().format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';  
       htmlMgr15 = '<p>You are receiving this email as one of your accounts may not have billed at least 15 days after its expected subscription end date. Please raise corresponding subscription/membership opportunity.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+mgrList.size()+'</br><i>As of:&nbsp;'+datetime.now().addDays(-15).format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';  
          
       for(Account accMgr:mgrList)
        {
       
            toAddressesMgr.Add(accMgr.Sales_Rep__r.User_account__r.Manager.Email); // add emails in Mgr array..
            dMgr = accMgr.Latest_Service_End_Date__c;
            dtMgr = Datetime.newInstance(dMgr.year(), dMgr.month(),dMgr.day());
            dateStringMgr= dtMgr.format(dateFormatString);
            s = accMgr.Days_Overdue_Missed_Invoice__c-15;
            htmlMgr += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accMgr.Id+'">'+accMgr.Name + '</a></td><td>'+accMgr.Sales_Rep__r.Name+'</td><td>' + dateStringMgr + '</td><td>'+accMgr.Days_Overdue_Missed_Invoice__c+'</td></tr>';
            htmlMgr15 += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accMgr.Id+'">'+accMgr.Name + '</a></td><td>'+accMgr.Sales_Rep__r.Name+'</td><td>' + Date.valueOf(dateStringMgr).format() + '</td><td>'+s+'</td></tr>';

            
        } 
             //close table...
            htmlMgr += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
            htmlMgr15 += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
              htmlAppendSP += htmlMgr15;
            htmlMgr += htmlAppendSP;    
            system.debug(htmlMgr);              
             
            // get unique Mgr emails in the array...           
            uniqueMgr.addAll(toAddressesMgr);
            toAddresses.AddAll(uniqueMgr);
          
              subjectSP = 'Second Escalation: Accounts with Missed Invoices';
              subjectSend = subjectMgr;
            htmlSend = htmlMgr;
              SS_EmailUtility.SendEmail(htmlSend, toAddresses, subjectSend); 
          
      } // end of IF for Mgr...
    
      if(cList.size()>0){   // check if Clevel missed invoice SOQL has returned row(s)..  
      
       htmlClevel = '<p>Escalating to Senior Executive Group as accounts listed below have not been billed for at least 45 days.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+cList.size()+'</br><i>As of:&nbsp;'+datetime.now().format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';          
       htmlC30 = '<p>Being the manager of the identified account managers, listed accounts have not been billed for at least 30 days.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+cList.size()+'</br><i>As of:&nbsp;'+datetime.now().addDays(-15).format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';  
       htmlC15 = '<p>You are receiving this email as one of your accounts may not have billed at least 15 days after its expected subscription end date. Please raise corresponding subscription/membership opportunity.</p><table border="1" style="border-collapse: collapse;text-align:left"><caption style="text-align:left"><u><b>Missed Invoice Summary Data:</b></u></br>Total Records:&nbsp;'+cList.size()+'</br><i>As of:&nbsp;'+datetime.now().addDays(-30).format()+'</i></caption><tr style="text-align:left"><th>Account Name</th><th>Account Owner</th><th>Last Service EndDate</th><th>Days Overdue</th></tr>';    
          
       for(Account accClevel:cList)
        {
       
            dClevel = accClevel.Latest_Service_End_Date__c;
            dtClevel = Datetime.newInstance(dClevel.year(), dClevel.month(),dClevel.day());
            dateStringClevel= dtClevel.format(dateFormatString);
            s = accClevel.Days_Overdue_Missed_Invoice__c-30;
            m = accClevel.Days_Overdue_Missed_Invoice__c-15;
            htmlClevel += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accClevel.Id+'">'+accClevel.Name + '</a></td><td>'+accClevel.Sales_Rep__r.Name+'</td><td>' + dateStringClevel + '</td><td>'+accClevel.Days_Overdue_Missed_Invoice__c+'</td></tr>';

            htmlC15 += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accClevel.Id+'">'+accClevel.Name + '</a></td><td>'+accClevel.Sales_Rep__r.Name+'</td><td>' + Date.valueOf(dateStringClevel).format() + '</td><td>'+s+'</td></tr>';
            htmlC30 += '<tr><td><a target="_blank" href=""'+system.label.Salesforce_Instance_URL+accClevel.Id+'">'+accClevel.Name + '</a></td><td>'+accClevel.Sales_Rep__r.Name+'</td><td>' + Date.valueOf(dateStringClevel).format() + '</td><td>'+m+'</td></tr>';
            
        } 
             
      // Select all user emails from Clevel PG...
      Group grp = [SELECT Id FROM Group Where DeveloperName ='Clevel_Users']; // fetch PG Id
      List<GroupMember> grpm = [SELECT UserOrGroupId FROM GroupMember Where GroupId =:grp.Id]; // fetch Group Users Id...
      Set<Id> grpmIds = new Set<Id>();  
      for(GroupMember grpmSet :grpm){
          grpmIds.add(grpmSet.UserOrGroupId);
            }
      List<User> cUsers = [SELECT Email FROM User Where Id=:grpmIds]; // fetch cleveluser's email.
        for(User cu: cUsers)  {
         toAddressesClevel.Add(cu.Email);  // add emails in clevel array..
         system.debug('Clevel Emails: '+toAddressesClevel); 
        }          
          
     //close table...
     htmlClevel += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
     system.debug(htmlClevel);              
     toAddresses = toAddressesClevel;               
     subjectClevel = 'Third Escalation: Accounts with Missed Invoices';
     subjectSend = subjectClevel;
          
     htmlC15 += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';
     htmlC30 += '</table></br>************************************************</br>This is an auto-generated email, please DO NOT REPLY.</br> ************************************************</br></br>';     
     htmlAppendSP += htmlC15;
     htmlAppendMgr += htmlC30;
     htmlAppendMgr += htmlAppendSP;     
     htmlClevel += htmlAppendMgr;
    
     htmlSend = htmlClevel;
     SS_EmailUtility.SendEmail(htmlSend, toAddresses, subjectSend); 
          
      } // end of IF for Clevel...
  
               
     } // end of execute constructor...
    
} // end of main class..

***********************************************************************

TEST CLASS:

@isTest 
private class SS_EscalationAlertsMIRTest {
    
     // Dummy CRON expression: midnight on May 1.
    // Because this is a test, job executes
   // immediately after Test.stopTest().
   
   public static String CRON_EXP = '0 0 0 1 5 ? 2019';
    
    static testmethod void testScheduledJob() { 
                
       // Create test Account record
        Account accs = new Account();
        Date servDate = Date.today().addDays(-45);
        accs.Name = 'Test';
        accs.Latest_Service_End_Date__c = servDate;
        
        // select profile.....
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];     
              
        User ManagerToCreate = new User(); //Create a manager user
        ManagerToCreate.Email='ManagerUserA@testorganise.com';
        ManagerToCreate.Alias = 'standard';
        ManagerToCreate.EmailEncodingKey='UTF-8';
        ManagerToCreate.LastName='Manager Test';
        ManagerToCreate.LanguageLocaleKey='en_US';
        ManagerToCreate.LocaleSidKey='en_US';
        ManagerToCreate.TimeZoneSidKey='America/Los_Angeles';
        ManagerToCreate.UserName='ManagerUserA@testorganise.com';
        ManagerToCreate.ProfileId = p.Id;
        insert ManagerToCreate;

        User userToCreate = new User(); // Create an Employee
        userToCreate.Email='UserA@testorganise.com';
        userToCreate.Alias = 'standard';
        userToCreate.EmailEncodingKey='UTF-8';
        userToCreate.LastName='User Test';
        userToCreate.LanguageLocaleKey='en_US';
        userToCreate.LocaleSidKey='en_US';
        userToCreate.TimeZoneSidKey='America/Los_Angeles';
        userToCreate.UserName='UserA@testorganise.com';
        userToCreate.ManagerId = ManagerToCreate.Id;  // Assign Manager to an Employee
        userToCreate.ProfileId = p.Id;
        insert userToCreate;
        
                                                           
       Test.startTest();
        
       system.runAs(userToCreate){
        
       // Setup shipserv person test data
       ShipServ_People__c sp = new ShipServ_People__c(Name='last', User_account__c=userToCreate.Id);
       insert sp;
       system.debug('id of user:'+sp.User_account__c+sp.User_account__c); 
            
        accs.Sales_Rep__c = sp.Id;   
        insert accs;  
        
        // Get the accounts that were just inserted       
        list<Account> uRetrieve = [select id from account]; //retrieve the record
        integer acc = uRetrieve.size();
        system.assertEquals(1,acc);//Test that the record is inserted
                       
        //Create public group...
        Group gp = new Group(Name = 'Test', DeveloperName='test');
        insert gp;
                      
        // Create group member...
        GroupMember gpm = new GroupMember();
        gpm.GroupId = gp.Id;
        gpm.UserOrGroupId = userToCreate.Id;
        insert(gpm);        
        system.debug('group member inserted:'+gpm.id);
           
        // Get the group member that's just inserted 
        list<GroupMember>gpmRetrieve = [select id from GroupMember where Group.DeveloperName='test']; //retrieve the record
        integer gpm2 = gpmRetrieve.size();
        system.assertEquals(1,gpm2);//Test that the record is inserted
           
       Id[] fixedSearchResults = new Id[2];
       fixedSearchResults[0] = accs.Id;
           
           
       // create an instance of the class... 
       SS_EscalationAlertsMIR mir = new SS_EscalationAlertsMIR();
       mir.htmlSP += 'test'+acc+datetime.now().format();
       mir.execute(null);    
          
       } // end of system.runAs...
                    
          // Schedule the test job
        String jobId = System.schedule('ScheduledApexTest',
            CRON_EXP, 
            new SS_EscalationAlertsMIR());
        
       // SS_EmailUtility.SendEmail('Unit Test X', new List<String>{'test@test.com'});
        
        Test.stopTest(); 

    }
}

Hi all, 

I have a question regarding the DATETIMEVALUE function. I'm creating a task each time a projects starts, and i would like to set the reminder at 09:30:00. So the date is based on a field, but the time should be fixed. I have tried multiple formulas, currently i have the following: 


DATETIMEVALUE(Customfield__c  & " " & 09:30:00) 

However, i receive an error that i miss a bracket: 

The formula expression is invalid: Syntax error. Missing ')'

Anyone any ideas? 

Kind regards, Loran

 

In the class i am accessing the parent record attribute with __r in the select query in child query like below .
Childrecord__c child = [ select Parentobj__r.Account__c  from childobject__c where name ='Test' limit 1 ];
if(child.Parentobj__r.Account__c != null)
{
do something();
}
In test class i have created parent and child record ,
but value of Parentobj__r.Account__c  always giving  null value while debug please help here ,