• TexasWheeling
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies
I'm having some difficulty with deploying an Apex Trigger and its Test Class. The trigger works great in my Sandbox environment, and the test class covers 96% code coverage. I'm fairly new to Apex coding and can not seem to figure out what is causing the error. Any suggestions would be great!


Apex Trigger Code:

trigger activeWebsites on Account (before Insert, before Update) {
    //Updating the "Active Website(s)" field
    for(Account a : Trigger.New) {
        // Ford (Elite)
        if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Ford (Elite)';
        }
        //Ford (Elite) & Lincoln (Base)
        else if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c == 'Live') {
            a.Active_Website_s__c = 'Ford (Elite) & Lincoln (Base)';
        }
        //Ford (Elite) & Lincoln (Elite)
        else if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c == 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Ford (Elite) & Lincoln (Elite)';
        }
        //Lincoln (Base)
        else if(a.FordElite_Status__c != 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c == 'Live') {
            a.Active_Website_s__c = 'Lincoln (Base)';
        }
        //Lincoln (Elite)
        else if(a.FordElite_Status__c != 'Live' && a.Lincoln_Elite_Status__c == 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Lincoln (Elite)';
        }
        //Toyota (Lite)
        else if(((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Toyota (Lite)';
        }
        //Toyota (Pro)
        else if(((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Toyota (Pro)';
        }
        //Toyota (Lite) & Scion
        else if((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.Franchise_s__c.contains('Scion') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Toyota (Lite) & Scion';
        }
        //Toyota (Pro) & Scion
        else if((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.Franchise_s__c.contains('Scion') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Toyota (Pro) & Scion';
        }
        //Scion
        else if((a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c != 'Core' || a.FUSION_WEB__c != 'Pro') && a.Web_Effective_Date__c == null) || (a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c == 'Core' || a.FUSION_WEB__c == 'Pro') && a.Web_Effective_Date__c == null) || (a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c != 'Core' || a.FUSION_WEB__c != 'Pro') && a.Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Scion';
        }
        //Acura (Core)
        else if(a.Franchise_s__c == 'Acura' && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Acura (Core)';
        }
        //Acura (Pro)
        else if(a.Franchise_s__c == 'Acura' && a.FUSION_WEB__c == 'Premium' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Acura (Pro)';
        }
        //Honda
        else if(a.Franchise_s__c == 'Honda' && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Honda';
        }
        //Other
        else if((a.RecordTypeId == '012A0000000q4l1' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c != 'Acura' && a.Franchise_s__c != 'Honda' && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Other';
        }
        //Null
        else {
            a.Active_Website_s__c = null;
        }
    }
}


Apex Text Class:

@isTest
public class Test_activeWebsites {
    static testMethod void testRecordCreation() {
  
    //Create Ford (Elite) Account
    Account a1 = new Account();
    a1.RecordTypeId = '012G0000000qG8j';
    a1.Name = 'Ford (Elite)';
    a1.Franchise_s__c = 'Ford';
    a1.FordElite_Status__c = 'Live';
    insert a1;
  
    //Create Ford (Elite) & Lincoln (Base) Account
    Account a2 = new Account();
    a2.RecordTypeId = '012G0000000qH4j';
    a2.Name = 'Ford (Elite) & Lincoln (Base)';
    a2.Franchise_s__c = 'Ford; Lincoln';
    a2.FordElite_Status__c = 'Live';
    a2.Lincoln_Base_Status__c = 'Live';
    insert a2;
  
    //Create Ford (Elite) & Lincoln (Elite) Account
    Account a3 = new Account();
    a3.RecordTypeId = '012G0000000qH4j';
    a3.Name = 'Ford (Elite) & Lincoln (Elite)';
    a3.Franchise_s__c = 'Ford; Lincoln';
    a3.FordElite_Status__c = 'Live';
    a3.Lincoln_Elite_Status__c = 'Live';
    insert a3;
  
    //Create Lincoln (Base) Account
    Account a4 = new Account();
    a4.RecordTypeId = '012G0000000qH4e';
    a4.Name = 'Lincoln (Base)';
    a4.Franchise_s__c = 'Lincoln';
    a4.Lincoln_Base_Status__c = 'Live';
    insert a4;
  
    //Create Lincoln (Elite) Account
    Account a5 = new Account();
    a5.RecordTypeId = '012G0000000qH4e';
    a5.Name = 'Lincoln (Elite)';
    a5.Franchise_s__c = 'Lincoln';
    a5.Lincoln_Elite_Status__c = 'Live';
    insert a5;
  
    //Create Toyota (Lite) Account
    Account a6 = new Account();
    a6.RecordTypeId = '012A0000000q4l3';
    a6.Name = 'Toyota (Lite)';
    a6.Franchise_s__c = 'Toyota';
    a6.FUSION_WEB__c = 'Core';
    a6.Web_Effective_Date__c = system.TODAY();
    insert a6;
  
    //Create Toyota (Pro) Account
    Account a7 = new Account();
    a7.RecordTypeId = '012A0000000q4l3';
    a7.Name = 'Toyota (Pro)';
    a7.Franchise_s__c = 'Toyota';
    a7.FUSION_WEB__c = 'Pro';
    a7.Web_Effective_Date__c = system.TODAY();
    insert a7;
  
    //Create Toyota (Lite) & Scion Account
    Account a8 = new Account();
    a8.RecordTypeId = '012A0000000q4l3';
    a8.Name = 'Toyota (Lite) & Scion';
    a8.Franchise_s__c = 'Toyota; Scion';
    a8.FUSION_WEB__c = 'Core';
    a8.Web_Effective_Date__c = system.TODAY();
    a8.Scion_Web__c = 'Pro';
    a8.Scion_Web_Effective_Date__c = system.TODAY();
    insert a8;
  
    //Create Toyota (Pro) & Scion Account
    Account a9 = new Account();
    a9.RecordTypeId = '012A0000000q4l3';
    a9.Name = 'Toyota (Pro) & Scion';
    a9.Franchise_s__c = 'Toyota; Scion';
    a9.FUSION_WEB__c = 'Pro';
    a9.Web_Effective_Date__c = system.TODAY();
    a9.Scion_Web__c = 'Pro';
    a9.Scion_Web_Effective_Date__c = system.TODAY();
    insert a9;
  
    //Create Scion Account
    Account a10 = new Account();
    a10.RecordTypeId = '012A0000000q4l3';
    a10.Name = 'Scion';
    a10.Franchise_s__c = 'Scion';
    a10.Scion_Web__c = 'Pro';
    a10.Scion_Web_Effective_Date__c = system.TODAY();
    insert a10;
  
    //Create Acura (Core) Account
    Account a11 = new Account();
    a11.RecordTypeId = '012G0000000qF9V';
    a11.Name = 'Acura (Core)';
    a11.Franchise_s__c = 'Acura';
    a11.FUSION_WEB__c = 'Core';
    a11.Web_Effective_Date__c = system.TODAY();
    insert a11;
  
    //Create Acura (Pro) Account
    Account a12 = new Account();
    a12.RecordTypeId = '012G0000000qF9V';
    a12.Name = 'Acura (Pro)';
    a12.Franchise_s__c = 'Acura';
    a12.FUSION_WEB__c = 'Premium';
    a12.Web_Effective_Date__c = system.TODAY();
    insert a12;
  
    //Create Honda Account
    Account a13 = new Account();
    a13.RecordTypeId = '012G0000000qF9V';
    a13.Name = 'Honda';
    a13.Franchise_s__c = 'Honda';
    a13.FUSION_WEB__c = 'Pro';
    a13.Web_Effective_Date__c = system.TODAY();
    insert a13;
  
    //Create Other Account
    Account a14 = new Account();
    a14.RecordTypeId = '012A0000000q4l1';
    a14.Name = 'Other';
    a14.Franchise_s__c = 'Jeep';
    a14.FUSION_WEB__c = 'Pro';
    a14.Web_Effective_Date__c = system.TODAY();
    insert a14;
  
    }
}


Deployment Failure Error:

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, activeWebsites: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.activeWebsites: line 41, column 1: []", Failure Stack Trace: "Class.M...

I have an email service setup to automatically create records within a custom object that we have setup. The email service parses the email's Subject into the name of the new record, and the email's Body into a "Description" custom field within the new record.

The email service works great, and can parse the email's content perfectly regardless of whether the email is plain text or an html email. However, whenever an html email goes through the email service, it adds the following html tag to the beginning of the "Description" field.

p{margin-top:0px; margin-bottom:0px;}

 Here's the code of the Apex Class I am using for this email service...

 

global class createMatrixRecordFromInboundEmail implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String myEmailBody = email.HTMLBody;
        IF(String.isNotBlank(myEmailBody)) {
            myEmailBody = email.HTMLBody;
        }
        ELSE {
            myEmailBody = email.plainTextBody;
        }
        List<Matrix_Team__c> mtrList = new List<Matrix_Team__c>();

        Matrix_Team__c mtr = new Matrix_Team__c(RecordTypeId = '012Z00000000WUD', OwnerId = '00GZ00000014KGG', Name = email.Subject, Description__c = myEmailBody);
        mtrList.add(mtr);
        insert mtrList;
        System.debug('New record(s): ' + mtrList);
       
        if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
            for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
                Attachment attachment = new Attachment();
                attachment.ParentId = mtr.Id;
                attachment.Name = email.binaryAttachments[i].filename;
                attachment.Body = email.binaryAttachments[i].body;
                insert attachment;
            }
        }

        result.success = true;

        return result;
    }
}

 

Do you know why the paragraph html tag is being added in whenever an html email goes through my email service?

Thanks!

Background Information: In my Salesforce Org we have Email-to-Case enabled and use it for our Customer Support team where emails from customers are automatically creating cases for the team to work from. The company I work for is a website design company, so an example case that we may receive from a customer would be creating new graphics for their website. This is our current process for this flow between the teams:

  1. Case is created from the customers email inquiry via Email-to-Case.
  2. Our Customer Support team recognizes that the case needs to be sent to our Graphics team and reassigns the case to the Graphics team's queue.
  3. The Graphics team works the case and then reassigns the case back to the original Customer Support person when the work is completed.
  4. The Customer Support person closes out the case.

Here is our issue: When a customer emails us about the status of the case, this email is automatically added to the case in the Emails related list section of the case. When the case is assigned to the Customer Support's User record, they would receive an email alert stating that a new email was added to the case. However, when the case is assigned to the Graphics Queue, the Customer Support person does not recieve the email alert since they are not the assigned owner at that time.

 

My Possible Solution: I have created a "Customer Support Rep" User lookup field on the Case to add in the User record for the Customer Support person working the case. I would like to have an email alert setup where it would grab the Email address from the User record listed in the "Customer Support Rep" field and send an email each time a new inbound email is added to the case.

 

My Stumbing Block: I know that this is not possible using a workflow since you can only perform Field Updates when creating a workflow from the Email Message object. Is it possible to create something for this through Apex coding? I am not too familiar with Apex coding yet, but I figured there might be a way to create a solution here.

 

Thanks for the help!

Here is the goal I am trying to achieve:

When a field named "Result of Call" on the Task object is updated to a specific value of "Conversation" for a Task with the record type of "Monthly Audit Call", I would like a trigger to update a field named "Monthly Audit Call" on the Account object to a specific value of "Completed". I would also like the "Monthly Audit Call" field on the Account object to be reset at the beginning of each month to the value of "Not Completed".

How could this be written in Apex to accomplish this? I am very new to Apex and have not yet learned how to write these triggers from scratch.

Thanks for the help!

My organization has Email-to-Case enabled and we have a process that we would like to create regarding closed cases when the case is generated through email-to-case.

We would like to have an automatic email response sent to a customer whenever they are responding to an email string that is attached to a closed case. In this email we will explain that they are responding to a closed case and that they will need to submit a new request from a new email.

I have attempted to do this through the use of a workflow on the "Email Message" object, however when I chose an action for this workflow I only have the option to choose "New Field Update" or "Select Existing Action". I do not see the "Email Alert" action available. The criteria on this workflow is the follow: (Email Message: Is IncomingequalsTrue) and (Case: Statusequals90 - Completed,91 - Closed - Unresponsive)

 

I have also attempted to seek help from Salesforce Support, but they informed me that it would require Apex Trgiggers and they were unable to help me with that.

Could someone helpe me out to create the Apex Trigger to accoplish this process?

I have a custom button that I have created which will send an email when it is clicked, however I am very new at this and can't seem to figure out how to deploy the new Apex Class to my Production environment. I have everything functioning the way I need in my Sandbox, but I'm struggling trying to create a test for this new Apex Class. Again, I am very new to this, so please forgive my ignorance on this subject.

 



The button has the behavior set to "Execute JavaScript" with the following OnClick JavaScript code:


{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
sforce.apex.execute("ReadyForTraining","SendEmailNotification", {Account:"{!Production__c.Account__c}",Production:"{!Production__c.Name}",Owner_FirstName:"{!User.FirstName}",Owner_LastName:"{!User.LastName}",Go_Live_Date:"{!Production__c.Actual_Go_Live_Date__c}",Product:"{!Production__c.Product__c}",FUSION_Tools_User:"{!Production__c.FusionTools_UserName__c}",FUSION_Tools_Pass:"{!Production__c.FusionTools_Password__c}",CallSource_User:"{!Production__c.CallSource_Username__c}",CallSource_Pass:"{!Production__c.CallSource_Password__c}",GA_User:"{!Production__c.Google_Analytics_Dealer_User_Name__c}",GA_Pass:"{!Production__c.Google_Analytics_Dealer_Password__c}",Production_Link:"{!Production__c.Link}"});
window.alert("Training email has been sent." );



The Apex Class has the following code:


global class ReadyForTraining {

WebService static void SendEmailNotification(string Account, string Production, string Owner_FirstName, string Owner_LastName, string Go_Live_Date, string Product, string FUSION_Tools_User, string FUSION_Tools_Pass, string CallSource_User, string CallSource_Pass, string GA_User, string GA_Pass, string Production_Link) {

//create a mail object to send a single email.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

//set the email properties
mail.setToAddresses(new string[] {'bpitts@clickmotive.com'});
mail.setSenderDisplayName('Implementation Team');
mail.setSubject('' + Account + ' - Ready For Training');
mail.setHtmlBody('Support,<br /><br />' + Account + ' is ready to have their training scheduled.<br /><br />Production: ' + Production + '<br />Owner: ' + Owner_FirstName + ' ' + Owner_LastName + '<br />Go Live Date: ' + Go_Live_Date + '<br />Product(s): ' + Product + '<br /><br /><table border="1" bordercolor="black"><tr bgcolor="#D4D4D4"><td><strong>Tool</strong></td><td><strong>Username</strong></td><td><strong>Password</strong></td></tr><tr><td>FUSION Tools</td><td>' + FUSION_Tools_User + '</td><td>' + FUSION_Tools_Pass + '</td></tr><tr><td>CallSource</td><td>' + CallSource_User + '</td><td>' + CallSource_Pass + '</td></tr><tr><td>Google Analytics</td><td>' + GA_User + '</td><td>' + GA_Pass + '</td></tr></table><br /><br />Production Record Link: ' + Production_Link + ''
);

//send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );

}
}



How would I properly write a test for this Apex Class so that I can deploy it to my Production environment?

I'm having some difficulty with deploying an Apex Trigger and its Test Class. The trigger works great in my Sandbox environment, and the test class covers 96% code coverage. I'm fairly new to Apex coding and can not seem to figure out what is causing the error. Any suggestions would be great!


Apex Trigger Code:

trigger activeWebsites on Account (before Insert, before Update) {
    //Updating the "Active Website(s)" field
    for(Account a : Trigger.New) {
        // Ford (Elite)
        if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Ford (Elite)';
        }
        //Ford (Elite) & Lincoln (Base)
        else if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c == 'Live') {
            a.Active_Website_s__c = 'Ford (Elite) & Lincoln (Base)';
        }
        //Ford (Elite) & Lincoln (Elite)
        else if(a.FordElite_Status__c == 'Live' && a.Lincoln_Elite_Status__c == 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Ford (Elite) & Lincoln (Elite)';
        }
        //Lincoln (Base)
        else if(a.FordElite_Status__c != 'Live' && a.Lincoln_Elite_Status__c != 'Live' && a.Lincoln_Base_Status__c == 'Live') {
            a.Active_Website_s__c = 'Lincoln (Base)';
        }
        //Lincoln (Elite)
        else if(a.FordElite_Status__c != 'Live' && a.Lincoln_Elite_Status__c == 'Live' && a.Lincoln_Base_Status__c != 'Live') {
            a.Active_Website_s__c = 'Lincoln (Elite)';
        }
        //Toyota (Lite)
        else if(((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Toyota (Lite)';
        }
        //Toyota (Pro)
        else if(((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c == null) || ((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c != 'Pro' && a.Scion_Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Toyota (Pro)';
        }
        //Toyota (Lite) & Scion
        else if((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.Franchise_s__c.contains('Scion') && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Toyota (Lite) & Scion';
        }
        //Toyota (Pro) & Scion
        else if((a.RecordTypeId == '012A0000000q4l3' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c.contains('Toyota') && a.Franchise_s__c.contains('Scion') && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Toyota (Pro) & Scion';
        }
        //Scion
        else if((a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c != 'Core' || a.FUSION_WEB__c != 'Pro') && a.Web_Effective_Date__c == null) || (a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c == 'Core' || a.FUSION_WEB__c == 'Pro') && a.Web_Effective_Date__c == null) || (a.Franchise_s__c.contains('Scion') && a.Scion_Web__c == 'Pro' && a.Scion_Web_Effective_Date__c != null && (a.FUSION_WEB__c != 'Core' || a.FUSION_WEB__c != 'Pro') && a.Web_Effective_Date__c != null)) {
            a.Active_Website_s__c = 'Scion';
        }
        //Acura (Core)
        else if(a.Franchise_s__c == 'Acura' && a.FUSION_WEB__c == 'Core' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Acura (Core)';
        }
        //Acura (Pro)
        else if(a.Franchise_s__c == 'Acura' && a.FUSION_WEB__c == 'Premium' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Acura (Pro)';
        }
        //Honda
        else if(a.Franchise_s__c == 'Honda' && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Honda';
        }
        //Other
        else if((a.RecordTypeId == '012A0000000q4l1' || a.RecordTypeId == '012G0000000qF9V' || a.RecordTypeId == '012G0000000qEhR') && a.Franchise_s__c != 'Acura' && a.Franchise_s__c != 'Honda' && a.FUSION_WEB__c == 'Pro' && a.Web_Effective_Date__c != null) {
            a.Active_Website_s__c = 'Other';
        }
        //Null
        else {
            a.Active_Website_s__c = null;
        }
    }
}


Apex Text Class:

@isTest
public class Test_activeWebsites {
    static testMethod void testRecordCreation() {
  
    //Create Ford (Elite) Account
    Account a1 = new Account();
    a1.RecordTypeId = '012G0000000qG8j';
    a1.Name = 'Ford (Elite)';
    a1.Franchise_s__c = 'Ford';
    a1.FordElite_Status__c = 'Live';
    insert a1;
  
    //Create Ford (Elite) & Lincoln (Base) Account
    Account a2 = new Account();
    a2.RecordTypeId = '012G0000000qH4j';
    a2.Name = 'Ford (Elite) & Lincoln (Base)';
    a2.Franchise_s__c = 'Ford; Lincoln';
    a2.FordElite_Status__c = 'Live';
    a2.Lincoln_Base_Status__c = 'Live';
    insert a2;
  
    //Create Ford (Elite) & Lincoln (Elite) Account
    Account a3 = new Account();
    a3.RecordTypeId = '012G0000000qH4j';
    a3.Name = 'Ford (Elite) & Lincoln (Elite)';
    a3.Franchise_s__c = 'Ford; Lincoln';
    a3.FordElite_Status__c = 'Live';
    a3.Lincoln_Elite_Status__c = 'Live';
    insert a3;
  
    //Create Lincoln (Base) Account
    Account a4 = new Account();
    a4.RecordTypeId = '012G0000000qH4e';
    a4.Name = 'Lincoln (Base)';
    a4.Franchise_s__c = 'Lincoln';
    a4.Lincoln_Base_Status__c = 'Live';
    insert a4;
  
    //Create Lincoln (Elite) Account
    Account a5 = new Account();
    a5.RecordTypeId = '012G0000000qH4e';
    a5.Name = 'Lincoln (Elite)';
    a5.Franchise_s__c = 'Lincoln';
    a5.Lincoln_Elite_Status__c = 'Live';
    insert a5;
  
    //Create Toyota (Lite) Account
    Account a6 = new Account();
    a6.RecordTypeId = '012A0000000q4l3';
    a6.Name = 'Toyota (Lite)';
    a6.Franchise_s__c = 'Toyota';
    a6.FUSION_WEB__c = 'Core';
    a6.Web_Effective_Date__c = system.TODAY();
    insert a6;
  
    //Create Toyota (Pro) Account
    Account a7 = new Account();
    a7.RecordTypeId = '012A0000000q4l3';
    a7.Name = 'Toyota (Pro)';
    a7.Franchise_s__c = 'Toyota';
    a7.FUSION_WEB__c = 'Pro';
    a7.Web_Effective_Date__c = system.TODAY();
    insert a7;
  
    //Create Toyota (Lite) & Scion Account
    Account a8 = new Account();
    a8.RecordTypeId = '012A0000000q4l3';
    a8.Name = 'Toyota (Lite) & Scion';
    a8.Franchise_s__c = 'Toyota; Scion';
    a8.FUSION_WEB__c = 'Core';
    a8.Web_Effective_Date__c = system.TODAY();
    a8.Scion_Web__c = 'Pro';
    a8.Scion_Web_Effective_Date__c = system.TODAY();
    insert a8;
  
    //Create Toyota (Pro) & Scion Account
    Account a9 = new Account();
    a9.RecordTypeId = '012A0000000q4l3';
    a9.Name = 'Toyota (Pro) & Scion';
    a9.Franchise_s__c = 'Toyota; Scion';
    a9.FUSION_WEB__c = 'Pro';
    a9.Web_Effective_Date__c = system.TODAY();
    a9.Scion_Web__c = 'Pro';
    a9.Scion_Web_Effective_Date__c = system.TODAY();
    insert a9;
  
    //Create Scion Account
    Account a10 = new Account();
    a10.RecordTypeId = '012A0000000q4l3';
    a10.Name = 'Scion';
    a10.Franchise_s__c = 'Scion';
    a10.Scion_Web__c = 'Pro';
    a10.Scion_Web_Effective_Date__c = system.TODAY();
    insert a10;
  
    //Create Acura (Core) Account
    Account a11 = new Account();
    a11.RecordTypeId = '012G0000000qF9V';
    a11.Name = 'Acura (Core)';
    a11.Franchise_s__c = 'Acura';
    a11.FUSION_WEB__c = 'Core';
    a11.Web_Effective_Date__c = system.TODAY();
    insert a11;
  
    //Create Acura (Pro) Account
    Account a12 = new Account();
    a12.RecordTypeId = '012G0000000qF9V';
    a12.Name = 'Acura (Pro)';
    a12.Franchise_s__c = 'Acura';
    a12.FUSION_WEB__c = 'Premium';
    a12.Web_Effective_Date__c = system.TODAY();
    insert a12;
  
    //Create Honda Account
    Account a13 = new Account();
    a13.RecordTypeId = '012G0000000qF9V';
    a13.Name = 'Honda';
    a13.Franchise_s__c = 'Honda';
    a13.FUSION_WEB__c = 'Pro';
    a13.Web_Effective_Date__c = system.TODAY();
    insert a13;
  
    //Create Other Account
    Account a14 = new Account();
    a14.RecordTypeId = '012A0000000q4l1';
    a14.Name = 'Other';
    a14.Franchise_s__c = 'Jeep';
    a14.FUSION_WEB__c = 'Pro';
    a14.Web_Effective_Date__c = system.TODAY();
    insert a14;
  
    }
}


Deployment Failure Error:

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, activeWebsites: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.activeWebsites: line 41, column 1: []", Failure Stack Trace: "Class.M...

I have an email service setup to automatically create records within a custom object that we have setup. The email service parses the email's Subject into the name of the new record, and the email's Body into a "Description" custom field within the new record.

The email service works great, and can parse the email's content perfectly regardless of whether the email is plain text or an html email. However, whenever an html email goes through the email service, it adds the following html tag to the beginning of the "Description" field.

p{margin-top:0px; margin-bottom:0px;}

 Here's the code of the Apex Class I am using for this email service...

 

global class createMatrixRecordFromInboundEmail implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String myEmailBody = email.HTMLBody;
        IF(String.isNotBlank(myEmailBody)) {
            myEmailBody = email.HTMLBody;
        }
        ELSE {
            myEmailBody = email.plainTextBody;
        }
        List<Matrix_Team__c> mtrList = new List<Matrix_Team__c>();

        Matrix_Team__c mtr = new Matrix_Team__c(RecordTypeId = '012Z00000000WUD', OwnerId = '00GZ00000014KGG', Name = email.Subject, Description__c = myEmailBody);
        mtrList.add(mtr);
        insert mtrList;
        System.debug('New record(s): ' + mtrList);
       
        if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
            for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
                Attachment attachment = new Attachment();
                attachment.ParentId = mtr.Id;
                attachment.Name = email.binaryAttachments[i].filename;
                attachment.Body = email.binaryAttachments[i].body;
                insert attachment;
            }
        }

        result.success = true;

        return result;
    }
}

 

Do you know why the paragraph html tag is being added in whenever an html email goes through my email service?

Thanks!

Background Information: In my Salesforce Org we have Email-to-Case enabled and use it for our Customer Support team where emails from customers are automatically creating cases for the team to work from. The company I work for is a website design company, so an example case that we may receive from a customer would be creating new graphics for their website. This is our current process for this flow between the teams:

  1. Case is created from the customers email inquiry via Email-to-Case.
  2. Our Customer Support team recognizes that the case needs to be sent to our Graphics team and reassigns the case to the Graphics team's queue.
  3. The Graphics team works the case and then reassigns the case back to the original Customer Support person when the work is completed.
  4. The Customer Support person closes out the case.

Here is our issue: When a customer emails us about the status of the case, this email is automatically added to the case in the Emails related list section of the case. When the case is assigned to the Customer Support's User record, they would receive an email alert stating that a new email was added to the case. However, when the case is assigned to the Graphics Queue, the Customer Support person does not recieve the email alert since they are not the assigned owner at that time.

 

My Possible Solution: I have created a "Customer Support Rep" User lookup field on the Case to add in the User record for the Customer Support person working the case. I would like to have an email alert setup where it would grab the Email address from the User record listed in the "Customer Support Rep" field and send an email each time a new inbound email is added to the case.

 

My Stumbing Block: I know that this is not possible using a workflow since you can only perform Field Updates when creating a workflow from the Email Message object. Is it possible to create something for this through Apex coding? I am not too familiar with Apex coding yet, but I figured there might be a way to create a solution here.

 

Thanks for the help!

I have a custom button that I have created which will send an email when it is clicked, however I am very new at this and can't seem to figure out how to deploy the new Apex Class to my Production environment. I have everything functioning the way I need in my Sandbox, but I'm struggling trying to create a test for this new Apex Class. Again, I am very new to this, so please forgive my ignorance on this subject.

 



The button has the behavior set to "Execute JavaScript" with the following OnClick JavaScript code:


{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
sforce.apex.execute("ReadyForTraining","SendEmailNotification", {Account:"{!Production__c.Account__c}",Production:"{!Production__c.Name}",Owner_FirstName:"{!User.FirstName}",Owner_LastName:"{!User.LastName}",Go_Live_Date:"{!Production__c.Actual_Go_Live_Date__c}",Product:"{!Production__c.Product__c}",FUSION_Tools_User:"{!Production__c.FusionTools_UserName__c}",FUSION_Tools_Pass:"{!Production__c.FusionTools_Password__c}",CallSource_User:"{!Production__c.CallSource_Username__c}",CallSource_Pass:"{!Production__c.CallSource_Password__c}",GA_User:"{!Production__c.Google_Analytics_Dealer_User_Name__c}",GA_Pass:"{!Production__c.Google_Analytics_Dealer_Password__c}",Production_Link:"{!Production__c.Link}"});
window.alert("Training email has been sent." );



The Apex Class has the following code:


global class ReadyForTraining {

WebService static void SendEmailNotification(string Account, string Production, string Owner_FirstName, string Owner_LastName, string Go_Live_Date, string Product, string FUSION_Tools_User, string FUSION_Tools_Pass, string CallSource_User, string CallSource_Pass, string GA_User, string GA_Pass, string Production_Link) {

//create a mail object to send a single email.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

//set the email properties
mail.setToAddresses(new string[] {'bpitts@clickmotive.com'});
mail.setSenderDisplayName('Implementation Team');
mail.setSubject('' + Account + ' - Ready For Training');
mail.setHtmlBody('Support,<br /><br />' + Account + ' is ready to have their training scheduled.<br /><br />Production: ' + Production + '<br />Owner: ' + Owner_FirstName + ' ' + Owner_LastName + '<br />Go Live Date: ' + Go_Live_Date + '<br />Product(s): ' + Product + '<br /><br /><table border="1" bordercolor="black"><tr bgcolor="#D4D4D4"><td><strong>Tool</strong></td><td><strong>Username</strong></td><td><strong>Password</strong></td></tr><tr><td>FUSION Tools</td><td>' + FUSION_Tools_User + '</td><td>' + FUSION_Tools_Pass + '</td></tr><tr><td>CallSource</td><td>' + CallSource_User + '</td><td>' + CallSource_Pass + '</td></tr><tr><td>Google Analytics</td><td>' + GA_User + '</td><td>' + GA_Pass + '</td></tr></table><br /><br />Production Record Link: ' + Production_Link + ''
);

//send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );

}
}



How would I properly write a test for this Apex Class so that I can deploy it to my Production environment?