0

I want to write test class for for below controller

Controller

public class OrederSendEmail {

public List<SelectOption> getEmailFrom() 
{

List<SelectOption> objNames = new List<SelectOption>();

List<OrgwideEmailAddress> org = [Select id,Address from OrgwideEmailAddress];

for(OrgwideEmailAddress name : org)

{

     objNames.add(new SelectOption(name.Id,name.Address));

}

return objNames;


}

    public List<SelectOption> getObjectNames() {
        List<SelectOption> objNames= new List<SelectOption>();
        objNames.add(new SelectOption('Account Receivables','Account Receivables'));
        objNames.add(new SelectOption('Asset','Asset'));
        objNames.add(new SelectOption('Bus Details','Bus Details'));
        objNames.add(new SelectOption('Campaign','Campaign'));
        objNames.add(new SelectOption('Account Receivables','Account Receivables'));
        objNames.add(new SelectOption('Case','Case'));
        objNames.add(new SelectOption('Contract','Contract'));
        objNames.add(new SelectOption('Course','Course'));
        objNames.add(new SelectOption('Product','Product'));
        objNames.add(new SelectOption('Asset','Asset'));
        objNames.add(new SelectOption('CustomOrder','CustomOrder'));
        objNames.add(new SelectOption('Contact','Contact'));
        objNames.add(new SelectOption('Practice','Practice'));
        objNames.add(new SelectOption('Order','Order'));

        return objNames;
    }

    public List<SelectOption> getMyPersonalTemplateOptions() {
        List<SelectOption> options = new List<SelectOption>();
        for (EmailTemplate t : [select Id,Name,Subject,body from EmailTemplate]) 
         {
            Maptemp.put(t.Id,t);
            options.add(new SelectOption(t.Id,t.Name));
        }
        return options;

    }
}

can any one help on this.

Thanks in advance.

  • 1
    what did you try so far – Tushar Sharma Aug 11 '16 at 7:06
1

You can try below code.

You need to instantiate the class and call the methods of that class:

@isTest                    
public class OrederSendEmailTest {

    public static testMethod void testOrederSendEmail() {
        OrederSendEmail controller = new OrederSendEmail();
        Test.startTest();
        List<SelectOption> emailFromOptns = controller.getEmailFrom();
        List<SelectOption> objectNamesOptns = controller.getObjectNames();
        List<SelectOption> myPersonalTemplateOptns = controller.getMyPersonalTemplateOptions();
        Test.stopTest();
        System.assertNotEquals(objectNamesOptns ,null);
    }   
}

See An Introduction to Apex Code Test Methods as a reference for writing Test Classes

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.