You need to sign in to do that
Don't have an account?

Hii All ,can anyone help me in increasing the code coverage of this trigger handler test class to 100%?
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;
try{
if(oppobj != null)
update oppobj;
}catch(Exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
isErrInSave = true;
}
}
}
TestClass:
@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
@testSetup
static void setupTestData(){
Account acc = TestUtility.createAccount('Test A');
insert acc;
Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
opp.Follow_up_Date__c = date.today();
insert opp;
}
testmethod static void saveOwnerTest(){
Opportunity opp = [Select id from Opportunity limit 1];
test.startTest();
Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
System.currentPageReference().getParameters().put('oppId',opp.id);
ApexPages.StandardController sc = new ApexPages.StandardController(opp);
ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
ctrlObj.saveOwner();
test.stopTest();
}
}
can any one help me to cover catch(Exception e) lines
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;
try{
if(oppobj != null)
update oppobj;
}catch(Exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
isErrInSave = true;
}
}
}
TestClass:
@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
@testSetup
static void setupTestData(){
Account acc = TestUtility.createAccount('Test A');
insert acc;
Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
opp.Follow_up_Date__c = date.today();
insert opp;
}
testmethod static void saveOwnerTest(){
Opportunity opp = [Select id from Opportunity limit 1];
test.startTest();
Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
System.currentPageReference().getParameters().put('oppId',opp.id);
ApexPages.StandardController sc = new ApexPages.StandardController(opp);
ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
ctrlObj.saveOwner();
test.stopTest();
}
}
can any one help me to cover catch(Exception e) lines
All Answers
Refer the below link have solution and modify the test data as per your code.
https://developer.salesforce.com/forums/?id=9060G000000MRo2QAG
If this helps, please mark it as best answer.
thanks!!
I think you are not able to cover the catch blog...So, you have to pass opp data which will fail in update due to some validation rule or trigger then you can cover the catch. Also, you can use the below trick to cover the catch block ...
Thanks,
Maharajan.C
صور س متحركه s | لا لـ صور سكس (س ك س s;s) | صور انمي Cool Anime pictures | اجمل الصور واتساب Best Profile Pictures for Whatsapp | منتديات نادي الشباب السعودي
خدمات موقع تساؤلات
Thank you for providing the solution. I will work on this to fix the error.
Thank you!
Here is our latest post, please have a look at the best Google Chrome extensions (https://www.allnewtechbuzz.info/best-google-chrome-extensions-for-seo/).
Feel free to visit my web page Minecraft apk mod free download check this site:-https://theminecrafts.com/
Feel free to visit my web page Minecraft apk mod here (https://theminecrafts.com/).
تحميل انستقرام بلس للايفون بدون جلبريك (https://www.baramjonline.com/2022/10/instagram-Plus-iphone-download.html)
تنزيل برنامج الاذان للهاتف بدون نت (https://www.baramjonline.com/2022/10/Download-Azan-Program.html)