• EchoMarc
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies

Hello,

 

I have an issue where I have conditional logic in a trigger that is based on the value of a formula field.  When running a functional test in the UI, this formula field evaluates fine and the trigger logic proceeds as expected.  When I run a testmethod with the same use case, the formula field does not evaluate and a bunch of code doesn't get covered.  

 

This is happening in two separate places in two different orgs.  I also have the debug logs to prove the formula field is getting evaluated in the functional test and not getting evaluated in the testmethod.

 

Has anyone ever run into this issue?  If so, how do you get around it without rewriting the trigger to mimic the formula field logic?

 

Thanks very much for any input!

I wrote an update trigger (tried both before and after update) on Case that checks some conditions and sends an email to the Case contact if they are true.

PROBLEM:  In the system logs, I’m seeing “Single email queued for send (pending commit)” and the email isn't sending.

Answers to obvious questions: I'm not seeing any errors in the logs, the trigger is firing okay and the field update I am doing in the trigger is happening.

Does anyone know why the email is not sending?  Here's the code:


trigger CaseClosedEmail on Case (before update) {
   
    List<Contact> cons;
    List<EmailTemplate> et = [Select Id From EmailTemplate Where DeveloperName ='CustomerSupportClose'];
    Set<Id> conIds = new Set<Id>();
    Map<Id, String> conInfo = new Map<Id, String>();
   
    //Put contactId of each case in a set so we can query the contacts
    for(Case c : trigger.new){
        conIds.add(c.ContactId);
    }
   
    //Get all the contacts of closed cases
    cons = [Select Id, Email From Contact Where Id in :conIds];
   
    //Put those contact IDs and their emails in a map
    if(cons.size() > 0 ){
        for(Contact c : cons){
            conInfo.put(c.Id, c.Email);
        }
    }

    for(Case c: trigger.new){
        if(c.Status == 'Closed'
        && conInfo.containsKey(c.ContactId)
        && et.size() == 1
        && c.Con_Close_Email_Sent__c == false){

            // Create a new single email message object
            // that will send out a single email to the addresses in the To list.
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           
            // Strings to hold the email addresses to which we are sending the email.
            String[] toAddresses = new String[] {conInfo.get(c.ContactId)};
           
            // Assign the addresses for the To and CC lists to the mail object.
            mail.setToAddresses(toAddresses);
           
            // Specify the address used when the recipients reply to the email.
            mail.setReplyTo('support@genomequest.com');
           
            // Specify the name used as the display name.
            mail.setSenderDisplayName('Genome Quest Support');
           
            // Specify the subject line for your email address.
            //mail.setSubject('Your case ' + c.Id + 'has been closed');
           
            // Don't append the salesforce.com email signature to the email.
            mail.setUseSignature(false);
           
            //The IDs to ensure that merge fields in the template contain the correct data.
            mail.setTargetObjectId(c.ContactId);
            mail.setWhatId(c.Id);
           
            // Specify the template content of the email.
            mail.setTemplateId(et[0].Id);
                           
            // Send the email you have created.
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
       
            c.Con_Close_Email_Sent__c = true;
           
        }
    }
   
}

 

Hi there,

 

I overrode the Task edit button with the following VF page.

 

Visualforce page code:

 

<apex:page standardController="Task" extensions="TaskEditOverride" action="{!getEditPage}" >
    <apex:form >
        <apex:outputText value="{!Task.Id} {!Task.MPDN_ID__c}" rendered="false"/>
    </apex:form>
</apex:page>

 

Controller Extension:

 

public class TaskEditOverride {
   
    ApexPages.Standardcontroller controller {get; set;}
    Task task {get; set;}
   
   
    /*Constructor*/
    public TaskEditOverride(ApexPages.Standardcontroller controller){
        this.controller = controller;
        this.task = (Task)controller.getRecord();
       
    }
   
    public PageReference getEditPage(){
        PageReference taskEdit = controller.edit(); 

        if(task.MPDN_ID__c == null){
            return taskEdit;

        } else {
            //This page exists
            return Page.Meeting;
        }


    }

}

 

 

Whenever I hit the edit button, it tries to load a big long URL about 20 times (looks like it's caught in some loop) and then finally settles on https://na1.salesforce.com/{!Task.Id}/e.  On that page, when I press Save or Edit, it reloads the https://na1.salesforce.com/{!Task.Id}/e page (so I'm caught in another loop).

 

I get the same behavior if I try to return new PageReference('/' + this.task.Id + '/e?retURL=%2F'+this.task.Id). 

 

Would anyone be so kind as to tell me why this seems to be happening? 

 

Much appreciated,

 

Marc

 

 

I wrote an update trigger (tried both before and after update) on Case that checks some conditions and sends an email to the Case contact if they are true.

PROBLEM:  In the system logs, I’m seeing “Single email queued for send (pending commit)” and the email isn't sending.

Answers to obvious questions: I'm not seeing any errors in the logs, the trigger is firing okay and the field update I am doing in the trigger is happening.

Does anyone know why the email is not sending?  Here's the code:


trigger CaseClosedEmail on Case (before update) {
   
    List<Contact> cons;
    List<EmailTemplate> et = [Select Id From EmailTemplate Where DeveloperName ='CustomerSupportClose'];
    Set<Id> conIds = new Set<Id>();
    Map<Id, String> conInfo = new Map<Id, String>();
   
    //Put contactId of each case in a set so we can query the contacts
    for(Case c : trigger.new){
        conIds.add(c.ContactId);
    }
   
    //Get all the contacts of closed cases
    cons = [Select Id, Email From Contact Where Id in :conIds];
   
    //Put those contact IDs and their emails in a map
    if(cons.size() > 0 ){
        for(Contact c : cons){
            conInfo.put(c.Id, c.Email);
        }
    }

    for(Case c: trigger.new){
        if(c.Status == 'Closed'
        && conInfo.containsKey(c.ContactId)
        && et.size() == 1
        && c.Con_Close_Email_Sent__c == false){

            // Create a new single email message object
            // that will send out a single email to the addresses in the To list.
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           
            // Strings to hold the email addresses to which we are sending the email.
            String[] toAddresses = new String[] {conInfo.get(c.ContactId)};
           
            // Assign the addresses for the To and CC lists to the mail object.
            mail.setToAddresses(toAddresses);
           
            // Specify the address used when the recipients reply to the email.
            mail.setReplyTo('support@genomequest.com');
           
            // Specify the name used as the display name.
            mail.setSenderDisplayName('Genome Quest Support');
           
            // Specify the subject line for your email address.
            //mail.setSubject('Your case ' + c.Id + 'has been closed');
           
            // Don't append the salesforce.com email signature to the email.
            mail.setUseSignature(false);
           
            //The IDs to ensure that merge fields in the template contain the correct data.
            mail.setTargetObjectId(c.ContactId);
            mail.setWhatId(c.Id);
           
            // Specify the template content of the email.
            mail.setTemplateId(et[0].Id);
                           
            // Send the email you have created.
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
       
            c.Con_Close_Email_Sent__c = true;
           
        }
    }
   
}

 

Hi there,

 

I overrode the Task edit button with the following VF page.

 

Visualforce page code:

 

<apex:page standardController="Task" extensions="TaskEditOverride" action="{!getEditPage}" >
    <apex:form >
        <apex:outputText value="{!Task.Id} {!Task.MPDN_ID__c}" rendered="false"/>
    </apex:form>
</apex:page>

 

Controller Extension:

 

public class TaskEditOverride {
   
    ApexPages.Standardcontroller controller {get; set;}
    Task task {get; set;}
   
   
    /*Constructor*/
    public TaskEditOverride(ApexPages.Standardcontroller controller){
        this.controller = controller;
        this.task = (Task)controller.getRecord();
       
    }
   
    public PageReference getEditPage(){
        PageReference taskEdit = controller.edit(); 

        if(task.MPDN_ID__c == null){
            return taskEdit;

        } else {
            //This page exists
            return Page.Meeting;
        }


    }

}

 

 

Whenever I hit the edit button, it tries to load a big long URL about 20 times (looks like it's caught in some loop) and then finally settles on https://na1.salesforce.com/{!Task.Id}/e.  On that page, when I press Save or Edit, it reloads the https://na1.salesforce.com/{!Task.Id}/e page (so I'm caught in another loop).

 

I get the same behavior if I try to return new PageReference('/' + this.task.Id + '/e?retURL=%2F'+this.task.Id). 

 

Would anyone be so kind as to tell me why this seems to be happening? 

 

Much appreciated,

 

Marc