function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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>();

        //loop
        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
                singleMail.setTargetObjectId(con.Id);

                //set template Id
                singleMail.setTemplateId(et.Id);

                //flag to false to stop inserting activity history
                singleMail.setSaveAsActivity(false);

                //add mail
                emails.add(singleMail);
            }
        }

        //send mail
        Messaging.sendEmail(emails);
        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:

@isTest
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;

        HelperContactTrigger.sendEmail(sendMail);
        System.assert(acc !=null);
        
        }
        }


thanks in advance :)

kiranmutturukiranmutturu
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
MithunPMithunP
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

http://salesforce.stackexchange.com/questions/18341/email-template-security

Best Regards,
Mithun.