You need to sign in to do that
Don't have an account?
Code Coveage : When value are dynamically picked using currentPage().getParameters()
Not getting the desired code coverage, need a trick to play around with this
I have a VF page that is providing a custom button on Standard Opportunity Page layout, and
a custom controller that handles the click event (a method)
Here is the VF page and part of controller code
VF page
======
<apex:page showHeader="false" standardController="Opportunity" extensions="ctrlMultiClone" action="{!createClone}" />
Controller
======
public PageReference createClone(){
oppid = ApexPages.currentPage().getParameters().get('id');
if(oppid != null)
{
List<Amenity_Billing__c> cons = new List<Amenity_Billing__c>();
Opportunity opp = [SELECT ID, StageName, Profit_Center__c,CloseDate,Name,Notice_Status__c,AccountId, LeadSource, Rate_Type__c FROM Opportunity WHERE Id = : oppid];
Opportunity oppCopy = opp.clone(false,true);
oppCopy.Name = oppCopy.Name +' '+ date.today();
insert oppCopy;
}
}
===============
Now when I m running the functionlaity everything works as desired... i.e.
I click on Custom, it calls the method createClone() in custom controller, this line get the current opportunity Id of the page
oppid = ApexPages.currentPage().getParameters().get('id');
and creates the clone....
But... when I m running created a code coverage I make a call to createClone() from test class..
as I have no way to pass this oppid when called from test class
requesting to please guide me a way out get "oopid" while creating a test class
thanks in advance
Sunny
Use code below :
All Answers
Use code below :
Thanks Balaji :)
I was creating Opportunity but this line is really helpful.
ApexPages.currentPage().getParameters().put('id', opp.id);