• Ramya Deshpande
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 0
    Replies
Batch Apex Class on custom object containing approval process,  to send an email to the approvers logged into the approval history related history of the custom object records ,
If at all the approval process status of the record is pending more than 24 hours
    We need 3 different email templates based on time delay, different email template should be triggered
a.    If Delayed between 24hrs and 48hrs – Email template for 24hr delay
b.    If Delayed between 48hrs and 72hrs – Email template for 48hr delay
c.    If Delayed more than 72hrs – Email template for 72hr delay
Below is the code written to achieve the above result .

global class FreightApprovalProcessBatch implements Database.Batchable<sobject>,Database.Stateful {
      
    List<Id> userList24 = new List<Id>();
    List<Id> userList48 = new List<Id>();
    List<Id> userList72 = new List<Id>();
        
    global Database.QueryLocator start(Database.BatchableContext bc)
    {        
        return 
            Database.getQueryLocator('SELECT ActorId,ElapsedTimeInHours, ProcessInstance.TargetObjectId,ProcessInstance.TargetObject.Name FROM ProcessInstanceWorkitem WHERE ElapsedTimeInHours > 24 AND ProcessInstanceId IN (SELECT Id FROM ProcessInstance WHERE Status = \'Pending\')');                         
    }   
    
    global void execute(Database.BatchableContext bc, List<ProcessInstanceWorkitem> scope)
    {        
        for(ProcessInstanceWorkitem p : scope)           
        {           
            Schema.SObjectType objectType = p.ProcessInstance.TargetObjectId.getSobjectType();
            if(objectType.getDescribe().getName().equals('Custom Object'))
            {              
                if(p.ElapsedTimeInHours >= 24 && p.ElapsedTimeInHours < 48 )
                {
                    userList24.add(p.ActorId);                 
                }
                
                else if(p.ElapsedTimeInHours >= 48 && p.ElapsedTimeInHours < 72)
                {
                    userList48.add(p.ActorId);                 
                }
                
                else if(p.ElapsedTimeInHours >= 72)
                {
                    userList72.add(p.ActorId); 
                }
            }             
        }
    }
    global void finish(Database.BatchableContext bc)
    {
        
        List <EmailTemplate> listTemplate = [Select id,name from EmailTemplate where name = 'Email Template 1' OR name = 'Email Template 2' OR name = 'Email Template 3'];   
        Id templateId24;
        Id templateId48;
        Id templateId72;
        for(EmailTemplate objEmailTemplate : listTemplate){
            
            if(objEmailTemplate.name == 'Email Template 1')
            {
                templateId24 = objEmailTemplate.Id;                
            }
            
            else if(objEmailTemplate.name == 'Email Template 2')
            {
                templateId48 = objEmailTemplate.Id;
            }
            
            else if(objEmailTemplate.name == 'Email Template 3')
            {
                templateId72 = objEmailTemplate.Id;
            }          
        }
              
        Messaging.MassEmailMessage emails24=new Messaging.MassEmailMessage(); 
        emails24.setTargetObjectIds(UserList24);       
        emails24.setTemplateID(templateId24);
        emails24.setSaveAsActivity(false);
        Messaging.SendEmail(New Messaging.MassEmailMessage[]{emails24}); 
                   
        Messaging.MassEmailMessage emails48=new Messaging.MassEmailMessage(); 
        emails48.setTargetObjectIds(UserList48);
        emails48.setTemplateID(templateId48);
        emails48.setSaveAsActivity(false);       
        Messaging.SendEmail(New Messaging.MassEmailMessage[]{emails48});
        
        Messaging.MassEmailMessage emails72=new Messaging.MassEmailMessage(); 
        emails72.setTargetObjectIds(UserList72);
        emails72.setTemplateID(templateId72);
        emails72.setSaveAsActivity(false);       
        Messaging.SendEmail(New Messaging.MassEmailMessage[]{emails72});   
    }    
}
Now, when I will run my above batch class in execute anonymous window, it is running successfully , even I am getting all those records to whom the email should be triggered.
Also, tried passing the hardcode userid's , then  I am able to receive an email .

But, when the batch is executed , I am not receiving any mails to my inbox.
So, please, let me know if some part of code is missing in the mass email messaging methods .
Also, we have created the different HTML email templates with the merge field in it, the merge fields are not populated in the received mails .
Also, let me know, how we should go and write test class for the same above class.
We have used standard salesforce survey component in community builder to submit the survey . The user is restricted to submit the survey only once , when the user tries to submit the survey again, the standard error occurs saying : - "An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information." which is the standard error. This error occurs when the user again tries to give feedback and submit. Requirement is to hide survey tab once the survey is submitted by the user .
Please, let me know if there are any settings in Survey component where we can check if the survey is submitted once by the specific user, then tha user should not be able to see the survey tab again on the community page.
We have used Feed, Post and Comment standard component on the community page. Now, our requirement is we need to hide the Answer section which comes under when we post any FAQ . Please, find the below image for reference.
User-added image

Already , tried by disabling Chatter setting options like:
1> Allow users to edit posts and comments 2> Allow users to compose rich text posts 3>Allow post pinning But, did not achieve any output from these settings. So, please let me know if there are any other settings we need to perform to hide the answer section from the Feed, Post and comment standard component I salesforce community.
Once we have created the public calendar in salesforce, how do we extend it in cutomer community ? 
What are exact steps to show it in customer community portal .
As we calculate login license user, For instance, if you purchased 20K logins, you can use 20K logins every month. Is the same calculation goes for API calls for Login License per user ? As per login license calculation, API calls calculation is also cumulative?
Implemented Dropdown menu list in developer instance we are getting the expected output.
    But, implemented the same dropdown menu list not working in UAT instance.
    Below is the code implemented for dropdown 
<nav id="navigation">
          <ul>
                  <li><a href="{!v.solutions}">Solutions</a></li>
                   <li><a href="{!v.techs}">Technical Services</a></li>
                   <li><a href="{!v.aboutus}">About us</a></li>
                   <li><a href="{!v.careers}">Careers</a></li>
                  <li><a href="{!v.contactus}">Contact Us</a></li>
            </ul>
       </nav>

Please, let me know what are the possible solutions for the same.
When we click on the link for e.g. : contact name ABC which is given in the content in the rich text field by giving the link as mailto:abc.abc@xyz.com
   it is linked with outlook i.e.OOB functionality , the outlook window also get opened but at the same time blank tab gets opened when we click on the mail link.
   Please, let me know what are the possible soution just to avoid the blank tab to be opened along with the outlook mail window.
 We have created rich text field to add the content in that field , where our content contains the product name as : 
   For e.g. Up Flow Reactor (UFR®) , On-Stream Catalyst Replacement (OCR®) Systems  
   where in the content itself we need to give superscript . 
   How to give superscript <sup> tag in the Rich text Field to achieve the output?
   Please, let me know what are the possible solutions for the same.