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
cjmarchicjmarchi 

unable to deploy controller extension to server!

Hello everyone,

I have been trying to deploy an extension controller to server from Eclipe IDE, but it says I have to write test class berfore doing that. I am newbie so I have no idea how to write test class for that purpose!

My extension controller saves my custom object data (Perfil_Cont__C) and redirects to contacts page linked to my custom object registry.

Code for controller extension:

public with sharing class Redireciona
{
   ApexPages.StandardController stdCtrl;
   // extension constructor
   public Redireciona(ApexPages.StandardController std)
   {
      stdCtrl=std;
   }

   public PageReference save()
   {
      stdCtrl.save();
      String newPageUrl = '/'+ ApexPages.currentPage().getParameters().get('id'); 
      PageReference pr= new PageReference(newPageUrl);
      pr.setRedirect(true);
      return pr;
   }
}

 Code for my visualforce page:

<apex:page standardController="Perfil_Cont__c" extensions="Redireciona">
    <apex:form >
       <apex:param name="Contato__c" value="{!$CurrentPage.parameters.contactId}"/>
       <apex:pageBlock id="blocoPagina" title="Informações de Perfil de Contato">
       
       <apex:messages />
       <apex:pageblockButtons location="bottom">
          <apex:commandButton action="{!Redireciona}" value="Salvar" />
          <apex:commandButton action="{!Cancel}" value="Cancelar" />
       </apex:pageblockButtons>
       
         <apex:actionRegion >
            <apex:pageBlockSection id="blocoSecao" columns="2">
               <apex:inputField value="{!Perfil_Cont__c.Contato__c}"></apex:inputField>
               <apex:inputField value="{!Perfil_Cont__c.Perfil__c}" required="true">
                  <apex:actionSupport event="onchange" status="statusid" reRender="blocoPagina" />
               </apex:inputField>
               <apex:actionStatus startText="Carregando..." id="statusid"></apex:actionStatus>
               <apex:inputField value="{!Perfil_Cont__c.OrganizacaoVinculada__c}" />
               <apex:inputField value="{!Perfil_Cont__c.Cargo__c}" />
               <apex:inputField value="{!Perfil_Cont__c.Per_odos__c}" /> 
               <apex:inputField value="{!Perfil_Cont__c.Observacoes__c}" />
            </apex:pageBlockSection>
         </apex:actionRegion>
         
         <apex:pageBlockSection rendered="{!Perfil_Cont__c.Perfil__c=='PROFESSOR'}" title="Informações de PROFESSOR" columns="2">
            <apex:inputField value="{!Perfil_Cont__c.Aposentado__c}" />
            <apex:inputField value="{!Perfil_Cont__c.Processo_de_Aprova_o__c}" required="{!Perfil_Cont__c.Perfil__c=='PROFESSOR'}" />
            <apex:inputField value="{!Perfil_Cont__c.Categoria_da_Institui_o__c}" />            
            <apex:inputField value="{!Perfil_Cont__c.Dias_da_Semana_que_Trabalha__c}" />
            <apex:inputField value="{!Perfil_Cont__c.rea_em_que_Leciona__c}" />
            <apex:inputField value="{!Perfil_Cont__c.Cursos_que_Leciona__c}" />
            <apex:inputField value="{!Perfil_Cont__c.S_rie_que_Leciona__c}" />
            <apex:inputField value="{!Perfil_Cont__c.Disciplinas_que_Leciona__c}" />                                    
         </apex:pageBlockSection>
         
         <apex:pageBlockSection rendered="{!Perfil_Cont__c.Perfil__c=='AUTOR'}" title="Informações de AUTOR" columns="2">
            <apex:inputField value="{!Perfil_Cont__c.Apelido__c}" />
            <apex:inputField value="{!Perfil_Cont__c.Data_do_Contrato__c}" />
            <apex:inputField value="{!Perfil_Cont__c.N_mero_do_Contrato__c}" />                                   
         </apex:pageBlockSection>
         
         <apex:pageBlockSection rendered="{!Perfil_Cont__c.Perfil__c=='TRADUTOR'}" title="Informações de TRADUTOR" columns="2">
            <apex:inputField value="{!Perfil_Cont__c.Idioma__c}" required="{!Perfil_Cont__c.Perfil__c=='TRADUTOR'}" />                                
         </apex:pageBlockSection>
         
         <apex:pageBlockSection rendered="{!Perfil_Cont__c.Perfil__c=='EQUIPE DE LIVRARIA'}" title="Informações de EQUIPE DE LIVRARIA" columns="2">
            <apex:inputField value="{!Perfil_Cont__c.rea_da_Livraria__c}" />                                
         </apex:pageBlockSection>
         
         <apex:pageBlockSection rendered="{!Perfil_Cont__c.Perfil__c=='COLABORADOR'}" title="Informações de COLABORADOR" columns="2">
            <apex:inputField value="{!Perfil_Cont__c.Fornecedor__c}" required="{!Perfil_Cont__c.Perfil__c=='COLABORADOR'}"/>                                
            <apex:inputField value="{!Perfil_Cont__c.rea_de_Atua_o__c}" />    
            <apex:inputField value="{!Perfil_Cont__c.Data_de_Acerto_de_Presta_o_de_Servi_os__c}" /> 
            <apex:inputField value="{!Perfil_Cont__c.Avalia_o_do_Trabalho__c}" />                           
         </apex:pageBlockSection>

         <apex:pageBlockSection rendered="{!Perfil_Cont__c.Perfil__c=='JORNALISTA'}" title="Informações de JORNALISTA" columns="2">
            <apex:inputField value="{!Perfil_Cont__c.Editoria__c}" />                                
            <apex:inputField value="{!Perfil_Cont__c.Informacoes_de_Reuni_o_de_Pauta__c}" />    
            <apex:inputField value="{!Perfil_Cont__c.Infromacoes_Data_de_Fechamento__c}" /> 
         </apex:pageBlockSection>

      </apex:pageBlock>
    </apex:form>
</apex:page>

Can anyone give me some ideas on that? 

Thanks a lot in advance!

Clarisse


 

TejTej

Go thru this doc will give u an idea regarding the test classes

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing.htm