You need to sign in to do that
Don't have an account?
Gorka Sanz
TestClass for a VF Controller
Hi to all.
I'm new in salesforce. I create a large number of apex classes with their testclasses without problem. But now i have a VF page with its own controller:
Controller
public class QADDatosFACTController {
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Account acc{get;set;}
public List<string> QADFACT {get;set;}
public String connQAD {get;set;}
public QADDatosFACTController(ApexPages.StandardController controller) {
try {
//recoger el parametro de conexion de QAD
string vName = 'QAD';
connQAD =[select ValorTexto__c from Parametros__c where Name = :vName].ValorTexto__c;
currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
acc = [select id ,name, AccountNumber, Type, ID_CLIENTE_QAD__c from Account where id =: currentRecordId ];
parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
// parseo de ordenes de venta
httpsIntegracionesCrmDvpClWscrmS.DvpWsCrmPort qad = new httpsIntegracionesCrmDvpClWscrmS.DvpWsCrmPort();
//httpsIntegracionesCrmDvpClWscrmS.getOvencResponseType resultado = qad.getOvenc ('1693090894a511ad4b8f1119c6a60b59','96792430');
httpsIntegracionesCrmDvpClWscrmS.getFacVenResponseType resultado = qad.getFacVen (connQAD,acc.ID_CLIENTE_QAD__c);
string json = resultado.facturas;
Getfact r = Getfact.parse(json);
//crear la lista de ordenes de venta
QADFACT = new List<String> ();
for(Integer i=1;i<r.facturasRow.size();i++)
{
QADFACT.add(r.facturasRow[i].invnbr);
}
}
catch (Exception e)
{
ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'Mensaje sin datos. Posible cliente sin facturas vencidas');
ApexPages.addMessage(errorMessage);
}
}
}
VF Page
<apex:page standardController="Account" extensions="QADDatosFACTController">
<!--All JS Libraries and CSS required for this example-->;
<apex:includeScript value="https://code.jquery.com/jquery-1.11.1.min.js"/>
<apex:includeScript value="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"/>
<apex:includeScript value="https://www.datatables.net/release-datatables/extensions/FixedColumns/js/dataTables.fixedColumns.js"/>
<apex:stylesheet value="https://cdn.datatables.net/1.10.7/css/jquery.dataTables.css"/>
<apex:stylesheet value="https://www.datatables.net/release-datatables/extensions/FixedColumns/css/dataTables.fixedColumns.css"/>
<apex:pagemessages />
<html>
<body>
<table id="accTable" class="display" cellspacing="0" width="100%">
<thead>
<th>Factura</th>
</thead>
<tbody>
<!-- Use apex:repeat to render each account record as a row and cell for the table-->
<apex:repeat value="{!QADFACT}" var="QAD">
<tr>
<td>{!QAD}</td>
</tr>
</apex:repeat>
</tbody>
</table>
</body>
</html>
This works fine in a sandbox. But i'm not able to create the correct testclass. This is my best effort:
@IsTest
public class testFacturasVencidasController {
static testMethod void testControladorFactVencidas()
{//inicio del metodo
//referencia a la pagina
test.startTest();
PageReference pageRef = Page.QAD_Facturas_Vencidas;
Test.setCurrentPage(pageRef);
//localizar una cuenta. Usar la que tengo como ejemplo de soap
list <Account> Cliente =[SELECT Id from Account where LLAVE_CRM__c = '12345678'];
//la llamada al controlador
ApexPages.StandardController sc = new ApexPages.StandardController(Cliente[0]);
QADDatosFACTController qad = new QADDatosFACTController(sc);
//List <QADDatosFACTController> lstqad = qad.QADFACT[0];
List <string> lstqad = qad.QADFACT;
test.stopTest();
}
}
What am i doing wrong? I need a bit of help.
Thanks in advance
I'm new in salesforce. I create a large number of apex classes with their testclasses without problem. But now i have a VF page with its own controller:
Controller
public class QADDatosFACTController {
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Account acc{get;set;}
public List<string> QADFACT {get;set;}
public String connQAD {get;set;}
public QADDatosFACTController(ApexPages.StandardController controller) {
try {
//recoger el parametro de conexion de QAD
string vName = 'QAD';
connQAD =[select ValorTexto__c from Parametros__c where Name = :vName].ValorTexto__c;
currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
acc = [select id ,name, AccountNumber, Type, ID_CLIENTE_QAD__c from Account where id =: currentRecordId ];
parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
// parseo de ordenes de venta
httpsIntegracionesCrmDvpClWscrmS.DvpWsCrmPort qad = new httpsIntegracionesCrmDvpClWscrmS.DvpWsCrmPort();
//httpsIntegracionesCrmDvpClWscrmS.getOvencResponseType resultado = qad.getOvenc ('1693090894a511ad4b8f1119c6a60b59','96792430');
httpsIntegracionesCrmDvpClWscrmS.getFacVenResponseType resultado = qad.getFacVen (connQAD,acc.ID_CLIENTE_QAD__c);
string json = resultado.facturas;
Getfact r = Getfact.parse(json);
//crear la lista de ordenes de venta
QADFACT = new List<String> ();
for(Integer i=1;i<r.facturasRow.size();i++)
{
QADFACT.add(r.facturasRow[i].invnbr);
}
}
catch (Exception e)
{
ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'Mensaje sin datos. Posible cliente sin facturas vencidas');
ApexPages.addMessage(errorMessage);
}
}
}
VF Page
<apex:page standardController="Account" extensions="QADDatosFACTController">
<!--All JS Libraries and CSS required for this example-->;
<apex:includeScript value="https://code.jquery.com/jquery-1.11.1.min.js"/>
<apex:includeScript value="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"/>
<apex:includeScript value="https://www.datatables.net/release-datatables/extensions/FixedColumns/js/dataTables.fixedColumns.js"/>
<apex:stylesheet value="https://cdn.datatables.net/1.10.7/css/jquery.dataTables.css"/>
<apex:stylesheet value="https://www.datatables.net/release-datatables/extensions/FixedColumns/css/dataTables.fixedColumns.css"/>
<apex:pagemessages />
<html>
<body>
<table id="accTable" class="display" cellspacing="0" width="100%">
<thead>
<th>Factura</th>
</thead>
<tbody>
<!-- Use apex:repeat to render each account record as a row and cell for the table-->
<apex:repeat value="{!QADFACT}" var="QAD">
<tr>
<td>{!QAD}</td>
</tr>
</apex:repeat>
</tbody>
</table>
</body>
</html>
This works fine in a sandbox. But i'm not able to create the correct testclass. This is my best effort:
@IsTest
public class testFacturasVencidasController {
static testMethod void testControladorFactVencidas()
{//inicio del metodo
//referencia a la pagina
test.startTest();
PageReference pageRef = Page.QAD_Facturas_Vencidas;
Test.setCurrentPage(pageRef);
//localizar una cuenta. Usar la que tengo como ejemplo de soap
list <Account> Cliente =[SELECT Id from Account where LLAVE_CRM__c = '12345678'];
//la llamada al controlador
ApexPages.StandardController sc = new ApexPages.StandardController(Cliente[0]);
QADDatosFACTController qad = new QADDatosFACTController(sc);
//List <QADDatosFACTController> lstqad = qad.QADFACT[0];
List <string> lstqad = qad.QADFACT;
test.stopTest();
}
}
What am i doing wrong? I need a bit of help.
Thanks in advance