+ Start a Discussion
KyoKyo 

Test Class not sync class Coverage Code 0%

public class MarkDeleteAccount{

 public MarkDeleteAccount(ApexPages.StandardController controller) {
    Acc = new Account(id = Apexpages.Currentpage().getParameters().get('id'));
        Acc.Mark_for_Delete__c = true;
        
  
  }
  
Public Account Acc {get;set;}
    
    public PageReference save(){     
       update Acc;
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
        
    
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
        
    }
  
    }

 

@isTest 
    private  class TestMarkDeleteAccount{
    static testMethod void myTest1() {
    
      List<Account> lstAcc = new List<Account>();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstAcc);
      
      Account  Acc = new Account();
      Acc.Name = 'Test Acc1';
      Acc.BP_Type__c = 'SCCC Mason';
      Acc.Mark_for_Delete__c = true;
      insert Acc;
      update Acc;
      ApexPages.currentPage().getParameters().put('id', Acc.Id); 
      Test.StartTest();
      sc.Save();
      sc.Cancel();
      Test.StopTest(); 
    }    
    
   
}

Test Class is 0% CodeCoverage. I can not make an error. 

Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

@isTest     private  class TestMarkDeleteAccount{ 

  static testMethod void myTest1() {

        test.starttest(); 

    Account  Acc = new Account(); 

    Acc.Name = 'Test Acc1'; 

    Acc.Mark_for_Delete__c = true;   

  insert Acc; 

    ApexPages.currentPage().getParameters().put('id', Acc.id);

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

      MarkDeleteAccount obj = new MarkDeleteAccount(sc);

      obj.save();   

  obj.Cancel(); 

    test.stoptest();   

            }

          }

 

All Answers

kiranmutturukiranmutturu

@isTest     private  class TestMarkDeleteAccount{ 

  static testMethod void myTest1() {

        test.starttest(); 

    Account  Acc = new Account(); 

    Acc.Name = 'Test Acc1'; 

    Acc.Mark_for_Delete__c = true;   

  insert Acc; 

    ApexPages.currentPage().getParameters().put('id', Acc.id);

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

      MarkDeleteAccount obj = new MarkDeleteAccount(sc);

      obj.save();   

  obj.Cancel(); 

    test.stoptest();   

            }

          }

 

This was selected as the best answer
KyoKyo

Yes it work.

Thank you so much.