Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
Can Anyone help me with the test class and make the code coverage to 100%

Apex class

public class QuotePDF {

    public boolean show{get;set;}

    public id pdtId{get;set;}

    public Quote op{get;set;}

    public QuoteLineItem oli{get;set;}

    public string pb{get;set;}

    public Id opid{get;set;}

    public id prodid{get;set;}

    public list<QuoteLineItem> OliList{get;set;}

    public list<Quotelineitem> OliCreate;

    public integer deleteIndex{get;set;}

    

    public QuotePDF()

    {

        show=false;

        oli=new QuoteLineItem();

        op=new Quote();

        OliList=new list<QuoteLineItem>();

        OliCreate=new list<Quotelineitem>();

    }

    

    public void save(){

        pricebook2 spbid=[select id from pricebook2 where isStandard=true limit 1];

        

        opportunity o1=[select id from opportunity limit 1];

        op.OpportunityId=o1.id;

        op.Pricebook2Id=spbid.id;

        upsert op;

        map<id,id>pdtTopbemap=new map<id,id>();

        

        for(pricebookentry pb:[select product2id,id from pricebookentry where pricebook2id =:spbid.id ])

        {

            pdtTopbemap.put(pb.product2id,pb.id);

        }

        for(QuoteLineItem o:OliList)

        {

            o.QuoteId=op.id;

            o.unitprice=o.unitprice; 

            o.quantity=o.quantity;

            o.pricebookentryid=pdtTopbemap.get(o.product2id);

            o.Product2Id=o.product2id;

            OliCreate.add(o);

        }

        insert OliCreate;

    }

    public void AddOli()

    {

        show=true;

        QuoteLineItem olitemp = new QuoteLineItem();

        OliList.add(olitemp);

    }

    

    public void deleteOpp()

    {

        OliList.remove(deleteIndex);

    }

}

Test Class

@isTest

Public class QuoteApexClassTest {

    @isTest public static void QuoteApextestMethod() {

        Opportunity opp = new Opportunity();

        opp.Name = 'TestOpp';

        opp.CloseDate = System.today() + 5;

        opp.StageName = 'Prospecting';

        Insert opp;

        

        Quote q = new Quote();

        q.Name = 'test';

        q.OpportunityId = opp.Id;

        Insert q;

        

       ApexPages.StandardController sc = new ApexPages.StandardController(q);

        PageReference pageRef = Page.QuoteTemplate;

        pageRef.getParameters().put('id', String.valueOf(q.Id));

        Test.setCurrentPage(pageRef);

    

        QuoteApexClass qac = new QuoteApexClass(sc);        

        qac.saveQuoteAsPDFandEmail();

        qac.attachPDF();

        qac.getShowPrintLink();

        qac.print();

    }

}

User-added image
1 answer
0/9000