function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rohini Chaudhary 14Rohini Chaudhary 14 

Hii All ,can anyone help me in increasing the code coverage of this test class

Apex Class:
public with sharing class ChangeOpptyOwnerCtrl {
    private string oppId;
    public Opportunity oppobj {get;set;}
    public boolean isErrInSave {get;set;}
    public ChangeOpptyOwnerCtrl(ApexPages.StandardController ctrl){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        if(oppId != null)
            oppobj = [Select id, Name, OwnerId from Opportunity where id =: oppId limit 1];
    public void saveOwner(){
        isErrInSave = false;
            if(oppobj != null)
                update oppobj;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
            isErrInSave = true;


public with sharing class ChangeOpptyOwnerCtrlTest {
    static void setupTestData(){
        Account acc = TestUtility.createAccount('Test A');
        insert acc;
        Opportunity opp = TestUtility.createOpportunity('@test opp',, 'To be Invoiced',;
        opp.Follow_up_Date__c =;
        insert opp;
    testmethod static void saveOwnerTest(){
        Opportunity opp = [Select id from Opportunity limit 1];
        Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
        ApexPages.StandardController sc = new ApexPages.StandardController(opp);
        ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);

can any one help me to cover 
catch(Exception e) lines
PriyaPriya (Salesforce Developers) 
Hi Rohini,

Can you please try adding one more method quering for opportunity where Opportunity opp should be empty.Something like below 
Select id from Opportunity where name='TestOpp'.

Hope this is helpful!

Rohini Chaudhary 14Rohini Chaudhary 14
plz can u explain it by writing it