Skip to main content
I am extremely limited in coding and stubled my way through to finally update the class I need and now I cannot deploy because my code coverage is too low.  This is incredibly frustrating, it says I am at 61% and need to get to 75% to deploy.  Any help would be greatly appreciated.  What can I do to get my coverage increased so I can deploy?

Apex Class

public class OpptyFlowController {

   public OpptyFlowController(ApexPages.StandardController controller) {

}

Public String profileName{get;set;}

public void NewContact()

    {

        Id profileId=userinfo.getProfileId();

        profileName=[Select Id,Name from Profile where Id=:profileId].Name;

    }

public Flow.Interview.NewOpptyButtonFlow myFlow { get; set; }

   

public String getmyID() {

if (myFlow==null) return '';

else return myFlow.var_NewOpptyId;

}

public PageReference getOID(){

PageReference p = new PageReference('/apex/opportunityProductEntry?&addto=' + getmyID() + '&retURL=%2F' + getmyID() + '&&sfdc.override=1&id='+ getmyID());

p.setRedirect(true);

return p;

}

}

Test Class

@isTest(SeeAllData=false)

public class OpptyFlowControllerTest {

public static testmethod void TheTest() {

     //Get User ID

     Id profileId='005D000000Akzri';

    //Insert Account

    Opportunity acct = new Opportunity(Name='VideoKilledTheRadioStar');

    

        acct.Name = 'Test Opportunity';

        acct.StageName = 'Long Term Project (180+ days)';

        acct.CloseDate = system.today();

        acct.Next_Step__c = 'Quote';

        acct.AccountID = '001D000000sPSFI';

    insert acct;

    

    // Retrieve the new Account

    acct = [SELECT Id,Name FROM Opportunity WHERE Id =:acct.Id];

    

    Quote Qt = new Quote(name='TestClassQuote');

    qt.F_A_O__c = 'EA';

    qt.OpportunityId = acct.ID;

        insert Qt;

    

    Qt = [Select ID, Name From Quote Where Id =:Qt.ID];

        

    SPA__c SPA = New SPA__c (name='TestClassSPA');

    Insert SPA;

    

    SPA = [Select ID, Name From SPA__c Where ID =:SPA.ID];

    

    String OpptyID = acct.Id;

    System.debug(OpptyID);

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

    OpptyFlowController ec = new OpptyFlowController(sc);

    

   PageReference FlowContractPageRef = Page.OQS_Flow_VF_Page;

    Test.setCurrentPage(FlowContractPageRef);

    string Var_NewOpptyID=opptyID;

    ec.getOID();

    ec.getmyID();

    

    System.test.startTest();

    System.debug('myID - Add myID'); 

    System.debug('myID - Save');

    System.test.stopTest();

   

    

}

}
4 answers
  1. Mar 3, 2021, 11:01 AM
    Hi Brian, 

    Let me know if the below covers the NewContact() method now

     

    @isTest(SeeAllData=false)

    public class OpptyFlowControllerTest {

    public static testmethod void TheTest() {

    //Get User ID

    Id profileId='005D000000Akzri';

    //Insert Account

    Opportunity acct = new Opportunity(Name='VideoKilledTheRadioStar');

    acct.Name = 'Test Opportunity';

    acct.StageName = 'Long Term Project (180+ days)';

    acct.CloseDate = system.today();

    acct.Next_Step__c = 'Quote';

    acct.AccountID = '001D000000sPSFI';

    insert acct;

    // Retrieve the new Account

    acct = [SELECT Id,Name FROM Opportunity WHERE Id =:acct.Id];

    Quote Qt = new Quote(name='TestClassQuote');

    qt.F_A_O__c = 'EA';

    qt.OpportunityId = acct.ID;

    insert Qt;

    Qt = [Select ID, Name From Quote Where Id =:Qt.ID];

    SPA__c SPA = New SPA__c (name='TestClassSPA');

    Insert SPA;

    SPA = [Select ID, Name From SPA__c Where ID =:SPA.ID];

    String OpptyID = acct.Id;

    System.debug(OpptyID);

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

    OpptyFlowController ec = new OpptyFlowController(sc);

    ec.NewContact();

    PageReference FlowContractPageRef = Page.OQS_Flow_VF_Page;

    Test.setCurrentPage(FlowContractPageRef);

    string Var_NewOpptyID=opptyID;

    ec.getOID();

    ec.getmyID();

    System.test.startTest();

    System.debug('myID - Add myID');

    System.debug('myID - Save');

    System.test.stopTest();

    }

    }

    Regards, 

    Anudeep
0/9000