• NightFox
  • NEWBIE
  • 0 Points
  • Member since 2015
  • Senior Software Engineer
  • Congruent India Pvt Ltd


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 8
    Replies

HI, Could you please guide me how to make the wrapper class object reactive in LWC js. 

I believe that @track properties are reactive but when I change the value of any property in `this.coreAttributes` js object, its not reflective in on `Save` button click 

Js file

import { LightningElement, track, api } from "lwc";
import queryCoreAttributes from "@salesforce/apex/P1PlantInfoPromptSolar.queryCoreAttributes";

export default class P1PlantInfoPromptSolar extends LightningElement {
@track coreAttributes;

connectedCallback() {
    queryCoreAttributes()
    .then(result => {
      this.coreAttributes = JSON.parse(result);
    }) 
    .catch({

    });

    this.promptSpecificAttributes = {
      noOfBlocks:"",
      flatHierarchy:false,
      drivePlus:false
    };
  }
saveP1PlantInfoPromptMetadataHandler(){
    console.log(' prompt specific att -> '+ JSON.stringify(this.coreAttributes));
  }
}
html file
<template for:each={coreAttributes} for:item="coreAttribute">
              <tr key={coreAttribute.key}>
                <th>{coreAttribute.attributeHeader}</th>
                <td>
                  <template if:false={coreAttribute.isPicklist}>
                    <input type={coreAttribute.attributeDataType} name={coreAttribute.attributeHeader}
                     value={coreAttribute.attributeValue}/>
                  </template>
                  <template if:true={coreAttribute.isPicklist}>
                    <select size="1" name={coreAttribute.attributeHeader}>
                      <option value="None">--None--</option>
                      <template for:each={coreAttribute.picklistValues} for:item="attributePickValues">
                        <option key={coreAttribute.key} value={coreAttribute.attributeValue}>{attributePickValues}</option>
                      </template>
                    </select>
                  </template>
                </td>
              </tr>
<lightning-button
        class="slds-m-left_small"
        variant="brand"
        label="Save"
        title="Save"
        onclick={saveP1PlantInfoPromptMetadataHandler}
      ></lightning-button>
            </template>


 
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'; 
    }
}




 
User-added image
Please Help,

Though the Action completion Date/time is not exceed the target Date/time, this is error message is shown while updating the milestone.

Please share your thoughts.   
 

Hi All,

Salesforce IP Range and Domain Whitelisting

During an integration with a 3rd party system, I have come across the issue, "Whitelisting the Salesforce IP Ranges and Domains". 
Salesforce knowledge article says and listed out several IP Ranges (eg: 182.50.78.5 - 182.50.78.15 - one of the APNIC range) to be whitelisted.

Here is my question, if the given(by Salesforce) IP's( 182.50.78.5 - 182.50.78.15 ) are whitelisted, all the organisation(Salesforce Org) lies in AP(Salesforce Asia Pacific Server) and whichever the organisation(Salesforce Org) using the same IP range to communicate with other system can have the access to our Server as well.
Hence, there is loophole and our Server firewall is exposed for all Salesforce Org's. This will not actually work not a right approach. 

We have to make sure that the request is coming from a authorized Salesforce Org. Is there anything we can get like a specific IP for one Salesforce Organisation? Something like this is necessary to make the Integration successful.
Please suggest me a good solution. 

Is it possible to whitelist the Custom Doimain Name "<mydomain>.my.salesforce.com"?

Regards,
Saravana.
 

I have created email-to-case also wrote a trigger(before and after insert) in EmailMessage Object, when I'm trying to access "BCcaddress" field in trigger level it gives NULL value even though I have sent an email by marking BCc to someone, also that field is not visible in EmailMessage standard page layout.

Do anyone have solution for this? I need to get "BCcaddress" field value in Trigger level.

here my code:

for(EmailMessage irow : trigger.new){
        if(irow.Incoming){
            system.debug(' Toaddress -> '+ irow.Toaddress + ' BCcaddress -> '+ irow.BCcaddress + ' Ccaddress -> '+ irow.Ccaddress + ' Fromaddress -> '+ irow.Fromaddress);
}}

 

Can anyone tellme why this below changes happening. If i create a datetime instance with date 2016-06-16 and time 12:00 then the debug shows different datetime like i have mentioned below. Thanks in advance.

Datetime dTime1 = Datetime.newInstance(2016, 06, 16, 12, 00, 00);   2016-06-16 12:00:00
Datetime dTime2 = Datetime.newInstance(2016, 06, 16, 1, 00, 00);     2016-06-16 01:00:00
system.debug('dTime1  '+dTime1);
system.debug('dTime2  '+dTime2);

|DEBUG| dTime1 -->  2016-06-16 06:30:00
|DEBUG| dTime2 -->  2016-06-15 19:30:00

HI, Could you please guide me how to make the wrapper class object reactive in LWC js. 

I believe that @track properties are reactive but when I change the value of any property in `this.coreAttributes` js object, its not reflective in on `Save` button click 

Js file

import { LightningElement, track, api } from "lwc";
import queryCoreAttributes from "@salesforce/apex/P1PlantInfoPromptSolar.queryCoreAttributes";

export default class P1PlantInfoPromptSolar extends LightningElement {
@track coreAttributes;

connectedCallback() {
    queryCoreAttributes()
    .then(result => {
      this.coreAttributes = JSON.parse(result);
    }) 
    .catch({

    });

    this.promptSpecificAttributes = {
      noOfBlocks:"",
      flatHierarchy:false,
      drivePlus:false
    };
  }
saveP1PlantInfoPromptMetadataHandler(){
    console.log(' prompt specific att -> '+ JSON.stringify(this.coreAttributes));
  }
}
html file
<template for:each={coreAttributes} for:item="coreAttribute">
              <tr key={coreAttribute.key}>
                <th>{coreAttribute.attributeHeader}</th>
                <td>
                  <template if:false={coreAttribute.isPicklist}>
                    <input type={coreAttribute.attributeDataType} name={coreAttribute.attributeHeader}
                     value={coreAttribute.attributeValue}/>
                  </template>
                  <template if:true={coreAttribute.isPicklist}>
                    <select size="1" name={coreAttribute.attributeHeader}>
                      <option value="None">--None--</option>
                      <template for:each={coreAttribute.picklistValues} for:item="attributePickValues">
                        <option key={coreAttribute.key} value={coreAttribute.attributeValue}>{attributePickValues}</option>
                      </template>
                    </select>
                  </template>
                </td>
              </tr>
<lightning-button
        class="slds-m-left_small"
        variant="brand"
        label="Save"
        title="Save"
        onclick={saveP1PlantInfoPromptMetadataHandler}
      ></lightning-button>
            </template>


 
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 All,

Salesforce IP Range and Domain Whitelisting

During an integration with a 3rd party system, I have come across the issue, "Whitelisting the Salesforce IP Ranges and Domains". 
Salesforce knowledge article says and listed out several IP Ranges (eg: 182.50.78.5 - 182.50.78.15 - one of the APNIC range) to be whitelisted.

Here is my question, if the given(by Salesforce) IP's( 182.50.78.5 - 182.50.78.15 ) are whitelisted, all the organisation(Salesforce Org) lies in AP(Salesforce Asia Pacific Server) and whichever the organisation(Salesforce Org) using the same IP range to communicate with other system can have the access to our Server as well.
Hence, there is loophole and our Server firewall is exposed for all Salesforce Org's. This will not actually work not a right approach. 

We have to make sure that the request is coming from a authorized Salesforce Org. Is there anything we can get like a specific IP for one Salesforce Organisation? Something like this is necessary to make the Integration successful.
Please suggest me a good solution. 

Is it possible to whitelist the Custom Doimain Name "<mydomain>.my.salesforce.com"?

Regards,
Saravana.
 

I have an Apex Class 'EmailPublisherLoader', which implements QuickAction.QuickActionDefaultsHandler, to set dynamic Email Templates, Recipients and From address in the Case Feed Email Publisher.

I am struggling with pushing the code to production, as the test class yields 74% coverage. I wonder which additional tests can be added to raise the test code coverage.

Below is the Apex Class:
 
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) {
            Case c = [SELECT Status, contact.Email, Additional_To__c, Additional_CC__c, Additional_BCC__c, RecordType.name FROM Case WHERE Id=:sendEmailDefaults.getContextId()];
            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();  

    //set TO address
         String contactEmail = c.contact.Email; 
         if (c.contact.Email == c.Additional_To__c){
            emailMessage.toAddress = (c.contact.Email);
            }
            else{
                if (c.Additional_To__c != null){
                    //contactEmail is included in Additional TO
                    if (c.Additional_To__c.indexOf(contactEmail) != -1){
                        emailMessage.toAddress = (c.Additional_To__c);
                        }
                else{
                    emailMessage.toAddress = (c.contact.Email+' '+c.Additional_To__c);
                    }
                }
            }
    //set CC address
            emailMessage.ccAddress = (c.Additional_CC__c);
    //set BCC address        
            emailMessage.bccAddress = (c.Additional_BCC__c);
    //set From 'security@test.com' for 'Security' RecordType
            if (c.recordtype.name  == 'Security'){
            emailMessage.fromAddress = ('security@test.com');
            }

    //if In Reply To Id field is null we know the interface is called on page load
        if (sendEmailDefaults.getInReplyToId() == null) {

                    if (c.recordtype.name  == 'Consumer'){
                        sendEmailDefaults.setTemplateId(getTemplateIdHelper('Custom_Default_Consumer_Email'));                       
                        }
                        else if (c.recordtype.name  == 'Security') {
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Custom_Default_Security_Email'));
                            } 
                            else {
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Custom_Default_Enterprise_Email'));
                            }                

           }
          // Now, we know that the 'Reply' or 'Reply All' button has been clicked, so we load the default response template 
          else
          {
               if (c.recordtype.name  == 'Consumer'){
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Custom_Default_Consumer_Email_No_Body'));
                            sendEmailDefaults.setInsertTemplateBody(true);
               }
               else if (c.recordtype.name  == 'Security') {
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Custom_Default_Security_Email'));
                            sendEmailDefaults.setInsertTemplateBody(true);
               }
                   else {
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Custom_Default_Enterprise_Email_No_Body'));
                            sendEmailDefaults.setInsertTemplateBody(true);
                   }      
          }
         }
       }

    private Id getTemplateIdHelper(String templateApiName) {
        Id templateId = null;
        try {
            templateId = [select id, name from EmailTemplate 
                          where developername = : templateApiName].id;   
        } catch (Exception e) {
            system.debug('Unble to locate EmailTemplate using name: ' + 
                templateApiName + ' refer to Setup | Communications Templates ' 
                    + templateApiName);
        }
        return templateId;
    }
}
And the Test Class:
@isTest
private class EmailPublisherLoaderTest {
    static Case myCase {get;set;}
    static EmailMessage myMsg {get;set;}

    static testmethod void EmailPublisherLoader_NoReplyToId() {
        Exception failureDuringExecution = null;
        init();
        init2();
        init3();
        init4();

        //create QuickActionDefaults
        List<Map<String, Object>> defaultSettingAsObject = new List<Map<String, Object>>
        {
          new Map<String, Object>
          {
                'targetSObject' => new EmailMessage(),
                'contextId' => myCase.Id,
                'actionType' => 'Email',
                'actionName' => 'Case.Email',
                'fromAddressList' => new List<String> { 'salesforce@test.com' }
          }
        };

        List<QuickAction.SendEmailQuickActionDefaults> defaultsSettings = 
            (List<QuickAction.SendEmailQuickActionDefaults>)JSON.deserialize(JSON.serialize(defaultSettingAsObject), List<QuickAction.SendEmailQuickActionDefaults>.class);
        Test.startTest();
        try {
            (new EmailPublisherLoader()).onInitDefaults(defaultsSettings);
        }
        catch(Exception e) {
            failureDuringExecution = e; 
        }

        Test.stopTest();
        System.assertEquals(null, failureDuringExecution, 'There was an exception thrown during the test!');
    }
    static testmethod void EmailPublisherLoader_WithReplyToId() {
        Exception failureDuringExecution = null;
        init();
        init2();
        init3();
        init4();

        //create QuickActionDefaults
        List<Map<String, Object>> defaultSettingAsObject = new List<Map<String, Object>>
        {
          new Map<String, Object>
          {
                'targetSObject' => new EmailMessage(),
                'replyToId' => myMsg.Id,
                'contextId' => myCase.Id,
                'actionType' => 'Email',
                'actionName' => 'Case.Email',
                'fromAddressList' => new List<String> { 'salesforce@test.com' }
          }
        };

        List<QuickAction.SendEmailQuickActionDefaults> defaultsSettings = 
            (List<QuickAction.SendEmailQuickActionDefaults>)JSON.deserialize(JSON.serialize(defaultSettingAsObject), List<QuickAction.SendEmailQuickActionDefaults>.class);
        Test.startTest();
        try {
            (new EmailPublisherLoader()).onInitDefaults(defaultsSettings);
        }
        catch(Exception e) {
            failureDuringExecution = e; 
        }

        Test.stopTest();
        System.assertEquals(null, failureDuringExecution, 'There was an exception thrown during the test!');
    }

    static void init(){
        myCase = 
            new Case(
                Status='Status'
                , Origin='Email'
                , Reason = 'Reason'
                , RecordTypeId = '01261000000XfOl'
            );
        insert myCase;

        myMsg = 
            new EmailMessage(
                ParentId = myCase.Id
            );
        insert myMsg;
    }
     static void init2(){
        myCase = 
            new Case(
                Status='Status'
                , Origin='Email'
                , Reason = 'Reason'
                , RecordTypeId = '01261000000XfOq'
            );
        insert myCase;

        myMsg = 
            new EmailMessage(
                ParentId = myCase.Id
            );
        insert myMsg;
    }
    static void init3(){
        myCase = 
            new Case(
                Status='Status'
                , Origin='Email'
                , Reason = 'Reason'
                , RecordTypeId = '01261000000iuJL'
            );
        insert myCase;

        myMsg = 
            new EmailMessage(
                ParentId = myCase.Id
            );
        insert myMsg;
    }
    static void init4(){
        myCase = 
            new Case(
                Status='Status'
                , Origin='Email'
                , Reason = 'Reason'
                , RecordTypeId = '01261000000XfP0'
            );
        insert myCase;

        myMsg = 
            new EmailMessage(
                ParentId = myCase.Id
            );
        insert myMsg;
    }
    @isTest
static void test_mockIfAtAllPossible(){
}
}



 
Hey all, 

I have a running implementation of a customized Email Publisher in the Case Feed, which implement QuickActionDefaultHandler to pre-populate Email Templates based on my Cases Record Type. Below is the Apex Class:
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) {
            Case c = [SELECT Status, contact.Email, Additional_To__c, Additional_CC__c, Additional_BCC__c, RecordType.name FROM Case WHERE Id=:sendEmailDefaults.getContextId()];
            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();  
    //set TO address
         if (c.contact.Email == c.Additional_To__c){
            emailMessage.toAddress = (c.contact.Email);
            }
            else{
            if (c.Additional_To__c != null){
            emailMessage.toAddress = (c.contact.Email+' '+c.Additional_To__c);
            }
            }

In addition, I am setting the TO address according a combination of the Case Contact and the custom field - 'Additional_To__c'. The above solution is setting the TO properly, but when the Case Contact does exist in the 'Additional_To__c' as follows:

User-added image

The outcome is a duplicity of the Case Contact - 'test@test.com': 
User-added image

How can I change the IF statement to avoid the above duplicitity? 

Hey guys,

We have an apex class and VF page called Register.  On this page the user can select from 4 different values on a picklist field called Type.

Is it possible to show all fours selections to all users that have Agent (checkbox) as TRUE on their user profile?

So what I would need is any currently logged in user with Agent as TRUE will see Options 1,2,3,4 and any user with Agent as FALSE will see options 1,2,3.

Can this be done?