You need to sign in to do that
Don't have an account?
Passing PARAM to Apex method from a test class
HI
My Vf code:
</apex:pageblock>
<apex:pageBlock title="New Route outlet" id="pb">
<apex:variable var="rowNumber" value="{!0}"/>
<apex:pageblockSection columns="1">
<apex:pageBlockTable title="Account" var="lro" value="{!outletWrapperList}">
<apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext">
<apex:outputText value="{0}" style="text-align:center;">
<apex:param value="{!rowNumber+1}" />
</apex:outputText>
<apex:facet name="footer">
<apex:commandlink action="{!addRouteoutlet}" value="Add Row" reRender="pb"/>
</apex:facet>
</apex:column>
<apex:column headerValue="Action" >
<apex:commandLink value="Delete" action="{!deleteRouteoutlet}" reRender="pb,mapPanel,map_canvas" oncomplete="showAddress();">
<apex:param name="rowIndex" value="{!rowNumber}"/>
</apex:commandlink>
<apex:variable var="rowNumber" value="{!rowNumber+1}"/>
</apex:column>
<apex:column headerValue="Account Name">
<apex:inputField value="{!lro.routeOutlet.Account__c}">
<apex:actionSupport event="onchange" action="{!addPopulatedAccounttoRouteOutlet}" reRender="pb,mapPanel,map_canvas" oncomplete="showAddress();">
<apex:param name="rowIndex" value="{!rowNumber-1}"/>
</apex:actionSupport>
</apex:inputField>
</apex:column>
:
:
Apex Code:
public void addPopulatedAccounttoRouteOutlet(){
rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
:
:
}
In Test class:
ApexPages.StandardController sc=new ApexPages.StandardController(rou);
rotout.addRouteoutlet();
rotout.addPopulatedAccounttoRouteOutlet();
& i am getting Error:
System.NullPointerException: Argument cannot be null.
Stack Trace Class.RouteOutlet_v3.addPopulatedAccounttoRouteOutlet:
Geeting Error in this line.
rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
Pls do help me to complete the test class
All Answers
that will convert the index to a string and add it to the parameters list.
Integer index = 2;
PageReference reference = Page.RouteOutlet_v3;
reference.getParameters().put('rowIndex', index);
This is the Errro Msg:
Incompatible value type Integer for MAP<String,String> at line.
This is the line:
reference.getParameters().put('rowIndex', index);
Hi Pcon,
i changed the code...
Integer index = 5;
PageReference reference = Page.RouteOutlet_v3;
reference.getParameters().put('rowIndex', String.valueOf(index));
rotout.addPopulatedAccounttoRouteOutlet();
Now again am getting the Same error:
System.NullPointerException: Argument cannot be null.
@ the function call,
public void addPopulatedAccounttoRouteOutlet(){
rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
:
:
}
rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
@isTest
private class TestRouteOutlet_v3 {
static testMethod void runTestRoutes() {
Account a = new Account(Name = 'Test Account ' ,BillingStreet = 'Test Street ' ,BillingCity = 'Test City ', BillingCountry = 'Test Country ' );
insert a;
City__c c = new City__c(Name = 'Test City ' );
insert c;
Route__c rou = new Route__c(Name = 'Test route ',Date__c = System.today(),City__c =c.ID);
insert rou;
Route_Outlet__c roulet = new Route_Outlet__c (Account__c=a.ID,Route__c =rou.id);
insert roulet ;
ApexPages.StandardController sc=new ApexPages.StandardController(rou);
RouteOutlet_v3 rotout = new RouteOutlet_v3(sc);
Integer index = 5;
PageReference reference = Page.RouteOutlet_v3;
reference.getParameters().put('rowIndex', String.valueOf(index));
rotout.addRouteoutlet();
//rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
//rotout.addRouteoutlet();
rotout.addPopulatedAccounttoRouteOutlet();
rotout.deleteRouteoutlet();
rotout.saveoutlet1();
}
}
This code worked for me , thank u Pcon,
Can u pls help me out here,
Getting error in this line.
Account acc=[Select id,BillingStreet,BillingCity,BillingState,BillingCountry,BillingPostalCode,Phone from Account where Id=: olwWrap.routeOutlet.Account__c];
Error msg:
System.QueryException: List has no rows for assignment to SObject