+ Start a Discussion
Bernd NawrathBernd Nawrath 

Debug statement for failing test class

Hello dear community, I was trying to create a class with a trigger so send mails autimatically when a new account is inserted. I'm getting this exception for a query that I have in my class as well as in my test class when I'm trying to run the test class: 
System.QueryException: List has no rows for assignment to SObject
Class.HelperContactTrigger.sendEmail: line 6, column 1 
Class.HelperContactTriggerTestneu.myTestMethod: line 17, column 1

I know it seems like there are no records found that should be returned. So how exactly is my debug statement supposed to look like to check if the account is really inserted?

These are the classes:

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

        //query on template object, is this correct,what might have been the mistake when I'm refering to EmailTemplate?
        EmailTemplate et=[Select id from EmailTemplate where name= 'Sales: New Customer Email' limit 1];

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

        for(Account con : accounts){
        //send mail

        return accounts;

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

        system.debug('### NewAccountTest ###');
        Account acc = new Account(Name = 'Test Test');
        insert acc;
                        // Here I'm refering to the test account that I have in my accounts
        List<Account> sendMail = [select id from account where (Name='Test Test') and id=:acc.id];

        System.assert(acc !=null);

thanks in advance! :)
Did you try to run by removing with sharing clause on the class?Can you post executable debug log for this