You need to sign in to do that
Don't have an account?
Liz Gibbons 16
New dev struggling with email automation and testing
Hi All,
I am writing a class to send an email follow-up when a community user hasn't logged in in 2 weeks. I think I have the class how it should be, but cannot figure out how to get the test class to cover the code.
The class:
The test class:
I'm pretty sure something needs to happen after
I am writing a class to send an email follow-up when a community user hasn't logged in in 2 weeks. I think I have the class how it should be, but cannot figure out how to get the test class to cover the code.
The class:
public class EmailFeedbackSurvey { public static void getFeedback(){ //date calculation for soql date d = system.today().addDays(-14); //list for feedback survey User[] u = [SELECT Id, Email, Contact.Name FROM User WHERE ProfileId = '00e16000000S7BU' AND LastLoginDate = Null]; User n = new User(); u.add(n); List<Messaging.SingleEmailMessage> feedbacks = new List<Messaging.SingleEmailMessage>(); for(Integer i= 0; i< u.size(); i++){ Messaging.SingleEmailMessage feedback = new Messaging.SingleEmailMessage(); List<String> sendTo = new List<String>(); sendTo.add(n.Email); feedback.setToAddresses(sendTo); feedback.setReplyTo('info@digitalonramps.com'); feedback.setSenderDisplayName('Digital On-Ramps'); feedback.setTemplateId('00X17000000Dqey'); feedbacks.add(feedback); } Messaging.sendEmail(feedbacks); } }
The test class:
@isTest public class EmailFeedbackSurveyTest { @isTest public static void emailUser(){ Id p = [SELECT id FROM Profile WHERE name = 'Learner Profile Community User'].id; Account acct = new Account(name= 'TestAcct'); insert acct; Contact con = new Contact(LastName = 'Learner', AccountId = acct.Id); insert con; User u = new User(alias = 'learner1', email = 'learner@testing.org', emailencodingkey='UTF-8', lastname='Learner', languagelocalekey='en_US', localesidkey='en_US', profileid = p, country='United States',IsActive =true, ContactId = con.Id, timezonesidkey='America/Los_Angeles', username='tester@noemail.com'); insert u; System.runAs(u){ EmailFeedbackSurvey test = new EmailFeedbackSurvey(); } } }
I'm pretty sure something needs to happen after
EmailFeedbackSurvey test = new EmailFeedbackSurvey();but I'm not sure what. I started coding last week, so I think I'm in a bit over my head with this.
EmailFeedbackSurvey test = new EmailFeedbackSurvey();EmailFeedbackSurvey.getFeedback();test.getFeedback();
All Answers
EmailFeedbackSurvey test = new EmailFeedbackSurvey();
test.getFeedback();
EmailFeedbackSurvey test = new EmailFeedbackSurvey();EmailFeedbackSurvey.getFeedback();test.getFeedback();