You need to sign in to do that
Don't have an account?
Deploying an Apex Class for a Custom Button
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 was able to get this corrected by changing the Apex Class API version to 24.0 and change the first line of the class' code from "@isTest" to "@isTest(seeAllData=false)". This resolved my issues.
All Answers
try this hope this will work for you
@isTest
private class TestGlobalClassEmail {
public static final String Account= 'Account of Test Email';
public static final String Production= 'Production of Test Email';
public static final String Owner_FirstName = 'Owner_FirstName of Test Email';
public static final String Owner_LastName = 'Owner_LastName of Test Email';
public static final String Go_Live_Date = 'Go_Live_Date of Test Email';
public static final String Product = 'Product of Test Email';
public static final String FUSION_Tools_User = 'FUSION_Tools_User of Test Email';
public static final String FUSION_Tools_Pass = 'FUSION_Tools_Pass of Test Email';
public static final String CallSource_User = 'CallSource_User of Test Email';
public static final String CallSource_Pass = 'CallSource_Pass of Test Email';
public static final String GA_User = 'GA_User of Test Email';
public static final String GA_Pass = 'GA_Pass of Test Email';
public static final String Production_Link = 'Production_Link of Test Email';
static testMethod void myUnitTest() {
ReadyForTraining.SendEmailNotification(Account, Production, Owner_FirstName, Owner_LastName, Go_Live_Date, Product, FUSION_Tools_User, FUSION_Tools_Pass, CallSource_User, CallSource_Pass, GA_User, GA_Pass, Production_Link);
}
}
Thanks, that worked for the test of the Apex Class that I am deploying, however now I have another test class that is failing on me now. It seems to be one that was already in my organization's environment and I am not familiar with it's purpose. Here is the portion of the code that is failing for the test class; this code is the beginning of line 246 for this class that is failing.
When I try to deploy the new Apex Class change set, I am getting the following error on this other test class:
API Name = V1CaseCollectorTestSuite.getCasesTest()
Type = Class
Line = 248
Column = 1
Problem = Failure Message: "System.Exception: Too many DML statements: 151", Failure Stack Trace: "Class.V1CaseCollectorTestSuite.getCasesTest: line 248, column 1"
Any ideas as to why I might be getting this error, and how I can go about correcting it so that I can correctly deploy my original change set?
Anyone have any thoughts on how to correct the last issue stated in the previous post?
I'm not sure if this will help, but this is an excert from the debug log on the test for this Apex Class.
I'm still at a loss on this one. Anyone out there with any suggestions?
I was able to get this corrected by changing the Apex Class API version to 24.0 and change the first line of the class' code from "@isTest" to "@isTest(seeAllData=false)". This resolved my issues.