You need to sign in to do that
Don't have an account?
Harsha Shri
Need help in test class for Messaging.Singleemailmessage and meta data
Hi All,
I have written a apex class to send email. I am new to test classes. I want to write test class for this. Please suggest how to cover my apex class.
This is my code.
Thanks in Advance
Please help me
I have written a apex class to send email. I am new to test classes. I want to write test class for this. Please suggest how to cover my apex class.
This is my code.
public class UtilityCont{ public static List<cotacts1__c> PSEContacts = new List<cotacts1__c>(); public static void EmailtoSRRTTeam(Instal_Prod__c IP) { try{ User usr = [select Id, username from User where Id = :UserInfo.getUserId()]; Account acc = [Select ShippingCountry from Account where id =: IP.Company__c]; PSEContacts = [Select Id,Email__c from cotacts1__c where Countries_in_Cluster__c =: acc.ShippingCountry]; EmailTemplate templateId = [Select id from EmailTemplate where name = :System.Label.SRRTEmailTemp]; if(usr!=null) { Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage(); list<String> toEmailIDs = new list<String>(); Integer i=0; for (cotacts1__c singleCCEmail: PSEContacts) { toEmailIDs.add(singleCCEmail.Email__c); mail.setTargetObjectId(userinfo.getUserId()); mail.setToAddresses(toEmailIDs); mail.setTreatTargetObjectAsRecipient(false); mail.setTemplateID(templateId.Id); mail.setWhatId(IP.Id); mail.setSaveAsActivity(false); } Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } catch(Exception ex) { } } public static String getUserContactNumber(){ ContactNumber__mdt record; try { String userLocale = UserInfo.getLocale(); String countryCode= userLocale.substring(3,5); record= [SELECT MasterLabel,DeveloperName,ContactNumber__c FROM ContactNumber__mdt where DeveloperName=:countryCode]; } catch(Exception ex) { } return record.ContactNumber__c; } }
Thanks in Advance
Please help me
Below are the link for "How to Write Test class ". Hope it will help.
http://www.sfdcpoint.com/salesforce/test-class-with-example-salesforce/
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
You can refer below links which will help you to write test class for single emailmessage.
https://salesforce.stackexchange.com/questions/96572/how-to-test-sendemailresult-for-singleemailmessage
Thanks,
Keyur Modi