• Arun Prasath 5
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
How to pre-populate FROM address in Email Publisher in the Case Feed. 
As far as I know My below code is correct. 

Here is the place where im passing the value for FROM Address fields. 
 
EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();    
// Set bcc address to make sure each email goes for audit
emailMessage.FromAddress = ('security@test.com');
emailMessage.ValidatedFromAddress = ('ValidatedFrom@address.com'); emailMessage.BccAddress = 'ff1@gmail.com';
emailMessage.CCAddress = 'bb1@gmail.com';
emailMessage.subject= 'Testing ';
emailMessage.ToAddress = 'toAdd@gmail.com';
Here is the Email publisher action page. See, all other fields are populated as per Apex definition. From address is only considering the ORG WIDE ADDRESS.

User-added image

Here is my full APEX code:
global class EmailPublisherLoader implements QuickAction.QuickActionDefaultsHandler {
    // Empty constructor
    global EmailPublisherLoader(){}
    
    // The main interface method
    global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults){
        QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null;
    
        // Check if the quick action is the standard Case Feed send email action
        for (Integer j = 0; j < defaults.size(); j++) {
            if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults && defaults.get(j).getTargetSObject().getSObjectType() == 
                   EmailMessage.sObjectType && defaults.get(j).getActionName().equals('Case.Email') &&  defaults.get(j).getActionType().equals('Email')){
                   sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(j);
                   break;
            }
        }
        
        if(sendEmailDefaults != null){
            system.debug(' sendEmailDefaults # ' + sendEmailDefaults  );
            system.debug(' sendEmailDefaults ID # ' + sendEmailDefaults.getcontextId()); 
            Case c = [SELECT Status, Casenumber,Reason FROM Case WHERE Id=:sendEmailDefaults.getContextId()];
            system.debug(' Case '+ c.CaseNumber);
            system.debug(' sendEmailDefaults.getTargetSObject() '+ sendEmailDefaults.getTargetSObject());
        
            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();    
            // Set bcc address to make sure each email goes for audit
            system.debug(' getBccAddress(c.Reason) # ' + getBccAddress(c.Reason) );
            system.debug(' getFromAddress(c.Reason) # ' + getFromAddress(c.Reason));
            //emailMessage.BccAddress = getBccAddress(c.Reason);
            //emailMessage.FromAddress = getFromAddress(c.Reason);
            emailMessage.FromAddress = ('security@test.com');
            emailMessage.ValidatedFromAddress = ('ValidatedFrom@address.com');
            emailMessage.BccAddress = 'ff1@gmail.com';
            emailMessage.CCAddress = 'bb1@gmail.com';
            //emailMessage.ValidatedFromAddress = 'tt1@gmail.com';
            emailMessage.subject= 'Testing ';
            emailMessage.ToAddress = 'toAdd@gmail.com';
            system.debug(' emailMessage '+ emailMessage );
            
            //sendEmailDefaults.ValidatedFromAddress = 'tt1@gmail.com';
            
            /* 
            Set Template related fields 
            When the In Reply To Id field is null we know the interface 
            is called on page load. Here we check if 
            there are any previous emails attached to the case and load 
            the 'New_Case_Created' or 'Automatic_Response' template.
            When the In Reply To Id field is not null we know that 
            the interface is called on click of reply/reply all 
            of an email and we load the 'Default_reply_template' template
            */
            
            system.debug(' sendEmailDefaults get Reply To '+ sendEmailDefaults.getInReplyToId());
            system.debug(' sendEmailDefaults getFrom Address '+ sendEmailDefaults.getFromAddressList());
            
            Integer emailCount = [SELECT count() FROM EmailMessage WHERE ParentId=:sendEmailDefaults.getContextId()];
            
            system.debug(' emailCount ' + emailcount );
            
            if(emailCount!= null && emailCount > 0){
                sendEmailDefaults.setTemplateId(
                getTemplateIdHelper('Send_Personal_Loan_Details'));
            }else{
                sendEmailDefaults.setTemplateId(
                getTemplateIdHelper('New_Case_Created'));
            }
            
            sendEmailDefaults.setInsertTemplateBody(false);
            sendEmailDefaults.setIgnoreTemplateSubject(true);
            
            system.debug(' sendEmailDefaults ### ' + sendEmailDefaults);
            
            /*
            if(sendEmailDefaults.getInReplyToId() == null){
                
            }else{
                sendEmailDefaults.setTemplateId(
                getTemplateIdHelper('Default_reply_template'));
                sendEmailDefaults.setInsertTemplateBody(false);
                sendEmailDefaults.setIgnoreTemplateSubject(true);
            }*/
        }
    }
    
    private Id getTemplateIdHelper(String templateApiName){
        Id templateId = null;
        try{
            templateId = [select id, name from EmailTemplate where developername = : templateApiName].id;
            system.debug(' Temp id # '+ templateId );   
        }catch(Exception e){
            system.debug('Unble to locate EmailTemplate using name: ' + templateApiName + ' refer to Setup | Communications Templates ' + templateApiName);
        }
        return templateId;
    }
    
    private String getBccAddress(String reason){
        return 'support_technical@mycompany.com, tt@gmail.com'; 
    }
    
    private String getFromAddress(String reason){
        return 'loan@mycompany.com, personalloan@gmail.com'; 
    }
}




 
Hi,
I have a VF page running in Lightning that save and cancel perfectly. I have modified it with slds markups to look likes Lightning and now when I try to save the record I got an error message "Attempt to de-reference a null object".The cancel button still works.

Any thought?

Shorten codes are as follow:

VF Page that works
<apex:page standardcontroller="Fact_Finder__c" extensions="FFFormCtrExt" showHeader="false" sidebar="false" >
<style type="text/css">
 .buttonsubmit {
  width: 200px;
  font-size: 150% !important;
  background:#E9EEF2 !important;
  }
.buttoncancel {
  width: 200px;
  font-size: 150% !important;
  background:#E9EEF2 !important;
  } 
 .pbHeader {
  font-size: 150%;
  background-color:#E9EEF2 !important; 
  border-radius: 5px;
 }
 .bPageBlock .pbTitle {
  width: 100%;    
  text-align: center; 
}   
</style> 
 <apex:form style="width:800px; text-align:center; margin:auto;" enctype="multipart/form-data" > 
  <apex:pageMessages />
   <apex:pageBlock id="block" title="Accident & Illness Fact Finder" >        
     <apex:pageBlockButtons location="bottom" > 
             <apex:commandButton action="{!saveFF}" value="Submit" styleclass="buttonsubmit" reRender="block" > 
               <apex:param name="p" value="{!$CurrentPage.Name}" assignTo="{!CurrentPageName}" />
            </apex:commandButton>                         
                        <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" styleClass="buttoncancel" />
                </apex:pageBlockButtons> 
<style>
 body .bPageBlock .pbBody .black .pbSubheader{
  background-color:#000000;
  font-size: 120%;  
  border-radius: 5px; 
}  
.bPageBlock .detailList  
{
  border-bottom:1px solid #000000;
  border-right:1px solid #000000;
  border-left:1px solid #000000;
  border-radius: 5px;  
}
 input {width: 95%;} 
 output {width: 95%;}
 textarea {
  width: 95%;
  height: 150px; 
 }  
 label {
  float: left;
  width: 150px;
  margin-left: 20px;
  text-align: left;
 }
 .radioB input, .radioB label{
   float:none;
   display:inline;
   width: 30px;
 }      
</style>              

    <apex:outputPanel styleClass="black" layout="block" >
              <apex:pageblocksection columns="1" >                         
                    <apex:inputfield value="{!FF.Opportunity_Name__c}" />            
                    <apex:inputfield value="{!FF.Client_Name__c}" />
                    <apex:inputfield value="{!FF.Date__c}" />                  
                    <apex:selectRadio value="{!FF.Attached_to__c}" styleclass="radioB" style="width:350px;" layout="pageDirection" > 
                      <apex:selectOption itemValue="Business Pack" itemlabel="Business Pack" />
                      <apex:selectOption itemValue="Farm Pack" itemlabel="Farm Pack" />
                    </apex:selectRadio>                                                 
     </apex:pageblocksection>  
</apex:outputPanel>         
    
    <apex:outputPanel styleClass="black" layout="block">
      <apex:pageblocksection title="Other Information" showheader="true" collapsible="true" columns="1">
                   <apex:actionSupport event="onchange" action="{!readUser}" />
          <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Prepared by"/>
                    <apex:inputField value="{!FF.Owner__c}"/>            
          </apex:pageBlockSectionItem>
                    <apex:inputfield value="{!FF.Notes__c}"/>
            </apex:pageblocksection>                 
     </apex:outputPanel>
     </apex:pageBlock>
  </apex:form>         
</apex:page>

VF Page that does not work
apex:page standardcontroller="Fact_Finder__c" extensions="FFFormCtrExt" standardStylesheets="false" applyBodyTag="false" >
 
 <apex:form >
  <apex:slds />
   <div class="slds-scope">

 <div class="slds-container--large slds-align_absolute-center">
  <div class="slds-page-header">
       <div class="slds-media__body">
            <h1 class="slds-page-header__title slds-align-middle">Accident and Illness Fact Finder</h1>
        </div>
  </div>
 </div> 

 <div class="slds-form slds-form_compound">
<fieldset class="slds-box slds-theme--default slds-container--medium slds-align_absolute-center">  

   <div class="slds-form-element">
   <div class="slds-form-element__group">
        <div class="slds-form-element__row">
          <div class="slds-form-element slds-size_1-of-2">
  <label class="slds-form-element__label" for="text-input-01">Opportunity Name</label>
         <apex:outputfield value="{!FF.Opportunity_Name__c}" styleClass="slds-input"/> 
         </div>             
<div class="slds-form-element slds-size_1-of-2">
  <label class="slds-form-element__label" for="text-input-01">Client Name</label>
       <apex:outputfield value="{!FF.Client_Name__c}" styleClass="slds-input"/>     
       </div>  
  </div> 
</div>
</div>
<div class="slds-form-element">
<div class="slds-form-element__group">
        <div class="slds-form-element__row">
          <div class="slds-form-element slds-size_1-of-2">
      <label class="slds-form-element__label" for="text-input-01">Date</label>
      <apex:inputfield value="{!FF.Date__c}" styleClass="slds-input"/>    
</div>
<div class="slds-form-element slds-size_1-of-2">
  <legend class="slds-form-element__legend slds-form-element__label">Attached to</legend>
  <apex:selectRadio value="{!FF.Attached_to__c}" styleclass="slds-input" layout="pageDirection" >
                    <apex:selectOption itemValue="Business Pack" itemlabel="Business Pack" />
                    <apex:selectOption itemValue="Farm Pack" itemlabel="Farm Pack" />
   </apex:selectRadio>   
   </div>
   </div>
   </div> 
</div>  
</fieldset>
</div>  
 
<fieldset class="slds-box slds-theme--default slds-container--medium slds-align_absolute-center">
     <legend id="otherinfoform" class="slds-text-heading--medium slds-p-vertical--medium">Other Information</legend>    
   
           <apex:actionSupport event="onchange" action="{!readUser}" />   
 <div class="slds-form-element"> 
  <label class="slds-form-element__label" for="text-input-01">Prepared by</label>
   <div class="slds-form-element__control">
       <apex:outputfield value="{!FF.Owner__c}" styleClass="slds-input"/>
    </div>
 </div>
 
 <div class="slds-form-element">
  <label class="slds-form-element__label" for="text-input-01">Notes</label>
   <div class="slds-form-element__control">
       <apex:inputfield value="{!FF.Notes__c}" styleClass="slds-input"/>
   </div>
</div>                         

     </fieldset>  
 <div class="slds-m-top--small"></div>
 <div class="slds-p-horizontal--small slds-m-top--medium slds-size--1-of-1 slds-align--absolute-center">
            <apex:commandButton action="{!saveFF}" value="Submit" styleclass="slds-button slds-button--brand" > 
               <apex:param name="p" value="{!$CurrentPage.Name}" assignTo="{!CurrentPageName}" />
            </apex:commandButton>                         
            <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" styleClass="slds-button slds-button--neutral" />
</div>

 </div>  
 </apex:form>  
</apex:page>

Same APEX Controller
public with sharing class FFFormCtrExt {

  public User selectedUser {get; set;}   
  public string CurrentPageName {get;set;}
 
  public Opportunity opp {get;set;}
  string recordId = ApexPages.currentPage().getParameters().get('recordId'); 
  public Fact_Finder__c FF {get; set;} 
  string FFId = ApexPages.currentPage().getParameters().get('FFId');   
 
     public FFFormCtrExt(ApexPages.StandardController controller) {    
      
       opp =  [SELECT Id, Name, ABN__c, ACN__c, Email__c, Phone__c, Address__c, Primary_Contact__c, Account.Name FROM Opportunity WHERE Id =:ApexPages.currentPage().getParameters().get('recordId')];      
   
       this.FF=(Fact_Finder__c)controller.getRecord();       
  
       FF.Opportunity_Name__c= recordId; 
            
       FF.Owner__c = UserInfo.getUserId();
       selectedUser = [ Select Id From User Where Id = :UserInfo.getUserId()];   
       
              
        } 
              
    public pageReference readUser()   {
        selectedUser = [ Select Id From User Where Id = :FF.Owner__c ];
        return null;      
    }      
                              
    public PageReference cancel(){   
     return new PageReference('/' + recordId);   
    }
    
    public PageReference saveFF() {           
      
      RecordType rt;             
      
            if(CurrentPageName == 'AccidentForm')   
            rt = [Select Id From RecordType Where DeveloperName = 'Accident_Illness' And sObjectType = 'Fact_Finder__c'];
        if(CurrentPageName == 'PIForm')   
            rt = [Select Id From RecordType Where DeveloperName = 'Professional_Indemnity' And sObjectType = 'Fact_Finder__c']; 
        if(CurrentPageName == 'GenericForm')   
            rt = [Select Id From RecordType Where DeveloperName = 'Generic' And sObjectType = 'Fact_Finder__c'];   
       
        FF.RecordTypeId = rt.Id;      
     
      
            insert (this.FF);           
        return new PageReference('/' + recordId); 
          
      }      
  }

Thanks,
Sylvie
I would like to achieve something like this:
User-added image

It is possible to do this using the Enhanced Page Layout Editor? Or it is only possible through VF page? This form have more than 200 fields by customer request and i don't want to code id...