Skip to main content
Hi everyone,

Please help me to write a test class for the following.

public  class acctTemplt

{

    public Id accountId {get;set;}

    public List<Opportunity> getopptys()

    {

        List<Opportunity> oppty;

        oppty = [SELECT Name, StageName FROM Opportunity ];

        return oppty;

    }

    public PageReference oppr(){

        List<Opportunity> oppty;

        oppty = [SELECT Name, StageName FROM Opportunity WHERE Accountid =: accountId];

        return  null;

    }

}
7 respuestas
  1. 16 jun 2016, 16:19
    Hi ,

    I just tested your code and test class in my org. Code coverage is 100%.

    @isTest

    public class acctTempltTest

    {

    static testMethod void testMethod1()

    {

    Account testAccount = new Account();

    testAccount.Name='Test Account' ;

    insert testAccount;

    Opportunity opp = new Opportunity(name= 'Opportunity', stagename='Prospecting',CloseDate=System.today().addMonths(1), Accountid=testAccount.id);

    insert opp;

    acctTemplt obj= new acctTemplt();

    List<Opportunity> oppList = obj.getopptys();

    obj.accountId = testAccount.id;

    obj.oppr();

    }

    }

    I just removed assert because from other trigger(in see in your other post) you are creating opp so count will be 2.

    Hi ,I just tested your code and test class in my org. Code coverage is 100%.

    Please let us know if you this will help you. If you are getting any error then please share screen shot of your error

     
0/9000