+ Start a Discussion
Bernd NawrathBernd Nawrath 

debugging for class

hello community, when I was executing with a debug to check on my class this occured:

User-added image

that's the code for the class:

public class HelperContactTrigger {
    //static method
    public static List<Account> sendEmail(List<Account> accounts) {

        //query on template object
        EmailTemplate et=[Select id from EmailTemplate where name= 'Sales: New Customer Email' limit 1];

        system.debug(et);   //debug to check the template

        //list of emails
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();

        for(Account con : accounts){

            //check for Account
            if(con.PersonEmail == null && con.PersonEmail != null){

                //initiallize messaging method
                Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();

                //set object Id

                //set template Id

                //flag to false to stop inserting activity history

                //add mail

        //send mail
        return accounts;

What do I do? I checked the code and everything a million times.
I was having difficulties running a test class for this programm (System.QueryException: List has no rows for assignment to SObject)
so I have to check if the query statement really does what it's supposed to, it has to work as a mailtrigger when a new account is added but the query is having issues so I have to know what the real problem is.

This is the test class:

private class HelperContactTriggerTestneuer {
public static testMethod void myTestMethod() {

        Account acc = new Account(Name = 'Test Test');
        insert acc;

        List<Account> sendMail = [select id from account where (Name='Test Test') and id=:acc.id];
   EmailTemplate testTemplate=new EmailTemplate(Name='Neuer Kunde',DeveloperName='Neuer_Kunde',FolderId=Userinfo.getUserId());
   insert testTemplate;

        System.assert(acc !=null);

thanks in advance :)

you should create an email template in the test class with the name "Sales: New Customer Email" so that it will be available in the run.

Also in the above code you gave a weird condition con.PersonEmail == null && con.PersonEmail != null... which seems to be corrected... 

also you need to populate the data for the account what you want in the main class too
Hi Bernd,

Do you have email template folder access, if not provide access on folder for profiles.

Checkout below link or navigate to Setup > Administer > Communication Templates > Email Templates


Best Regards,