+ Start a Discussion
Lago S.p.a.Lago S.p.a. 

Show VisualForce by setting a RecordType

Hi, I would like to see a particular Visualforce on setting a particular record type on a Contract.
The problem is that the page gaves a loop or this message: 
"The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores". 
Here's my controller:

public with sharing class ContractDiscoverPage {

private ApexPages.StandardController controller;
public String retURL {get; set;}
public String saveNewURL {get; set;}
public String rType {get; set;}
public String cancelURL {get; set;}
public String ent {get; set;}
public String confirmationToken {get; set;}
public String accountID {get; set;}
//public String contactID {get; set;}

public ContractDiscoverPage(ApexPages.StandardController controller) {

this.controller = controller;

//retURL = ApexPages.currentPage().getParameters().get('retURL');
rType = ApexPages.currentPage().getParameters().get('RecordType');
cancelURL = ApexPages.currentPage().getParameters().get('cancelURL');
ent = ApexPages.currentPage().getParameters().get('ent');
confirmationToken = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
saveNewURL = ApexPages.currentPage().getParameters().get('save_new_url');
accountID = ApexPages.currentPage().getParameters().get('def_account_id');
//contractID = ApexPages.currentPage().getParameters().get('def_contract_id');
}

public PageReference redirect() {

PageReference returnURL;

// Redirect if Record Type corresponds to custom VisualForce page

IF(rType == '012a0000001W9qA') {

returnURL = new PageReference('/apex/ContractDiscover/' + 'accountID' +  '?nooverride=1');

}

ELSE {

returnURL = new PageReference('/800/e');

}

returnURL.getParameters().put('retURL', retURL);
returnURL.getParameters().put('RecordType', rType);
returnURL.getParameters().put('cancelURL', cancelURL);
returnURL.getParameters().put('ent', ent);
returnURL.getParameters().put('_CONFIRMATIONTOKEN', confirmationToken);
returnURL.getParameters().put('save_new_url', saveNewURL);
returnURL.getParameters().put('nooverride', '1');
returnURL.getParameters().put('accid', accountID );
IF (accountID != null){

returnURL.getParameters().put('def_account_id', accountID);

}


returnURL.setRedirect(true);
return returnURL;

}
}

And this is my visualforce:

<apex:page standardController="Contract" extensions="ContractDiscoverPage" tabStyle="Contract" showheader="true" action="{!redirect}">
<apex:variable value="{!Contract.Account}" var="Account=Account"/>
  <h1>Contract</h1>
  <apex:define name="Header">
         <apex:sectionHeader title="{!$ObjectType.Contract.label}" subtitle="Contratto per: {'Contract.Account.Name}"/>
             <apex:form >
                <apex:inlineEditSupport event="ondblClick">
                <apex:pageBlock mode="view">
                    <apex:pageBlockButtons location="both">
                        <apex:commandButton value="Save" action="{!save}"/>
                        <apex:commandButton value="Cancel" action="{!cancel}"/>
                        <apex:commandButton action="{!delete}" value="Delete"/>
                        <apex:commandButton action="{!delete}" value="Contratto progettazione"/>
                    </apex:pageBlockButtons>
                    <apex:actionRegion >
                   
                    <apex:pageBlockSection id="section1" columns="3" title="Dettagli Contratto">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:outputField value="{!Contract.AccountId}"/>
                            <apex:outputField value="{!Contract.ContractNumber}" />
                            <apex:inputField value="{!Contract.RecordTypeId}"/> 
                            <apex:outputField value="{!Contract.invio_lett_intenti__c}" />
                            <apex:outputField value="{!Contract.Type__c}"/>
                            <apex:outputField value="{!Contract.Tipo__c}"/> 
                            <apex:outputField value="{!Contract.agente__c}"/>
                            <apex:outputField value="{!Contract.Status}"/>
                            <apex:outputField value="{!Contract.accordo_prog__c}"/>
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>
                        
                    <apex:pageBlockSection id="section2" columns="2" title="Condizioni Commerciali">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:outputField value="{!Contract.invio_lett_intenti__c}"/>
                            <apex:outputField value="{!Contract.ricez_lettera_intenti__c}" />
                            <apex:outputField value="{!Contract.StartDate}"/> 
                            <apex:outputField value="{!Contract.endContractDate__c}" />
                            <apex:outputField value="{!Contract.discount__c}"/>
                            <apex:outputField value="{!Contract.contract_sign_date__c}"/> 
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>  
                        
                    <apex:pageBlockSection id="section3" columns="2" title="Dati per Accordo Progettazione" rendered="{!Contract.accordo_prog__c=='Si'}">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:inputField value="{!Contract.CreatedById}"/>
                            <apex:inputField value="{!Contract.LastModifiedById}"/>
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>      
                    
                    <apex:pageBlockSection id="section4" columns="2" title="Informazioni sul sistema">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:inputField value="{!Contract.CreatedById}"/>
                            <apex:inputField value="{!Contract.LastModifiedById}"/>
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>  
                </apex:actionRegion>
                    
                </apex:pageBlock>
                </apex:inlineEditSupport>
             </apex:form>
  </apex:define>
</apex:page>

Any help will be very appreciated!!!!!! I'm very frustrated :(
Thanks!
Nayana KNayana K
<apex:page standardController="Contract" extensions="ContractDiscoverPage" tabStyle="Contract" showheader="true" action="{!redirect}">
<apex:variable value="{!Contract.Account}" var="Account"/>
  <h1>Contract</h1>
  <apex:define name="Header">
         <apex:sectionHeader title="{!$ObjectType.Contract.label}" subtitle="Contratto per: {!Contract.Account.Name}"/>
             <apex:form >
                <apex:inlineEditSupport event="ondblClick">
                <apex:pageBlock mode="view">
                    <apex:pageBlockButtons location="both">
                        <apex:commandButton value="Save" action="{!save}"/>
                        <apex:commandButton value="Cancel" action="{!cancel}"/>
                        <apex:commandButton action="{!delete}" value="Delete"/>
                        <apex:commandButton action="{!delete}" value="Contratto progettazione"/>
                    </apex:pageBlockButtons>
                    <apex:actionRegion >
                   
                    <apex:pageBlockSection id="section1" columns="3" title="Dettagli Contratto">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:outputField value="{!Contract.AccountId}"/>
                            <apex:outputField value="{!Contract.ContractNumber}" />
                            <apex:inputField value="{!Contract.RecordTypeId}"/> 
                            <apex:outputField value="{!Contract.invio_lett_intenti__c}" />
                            <apex:outputField value="{!Contract.Type__c}"/>
                            <apex:outputField value="{!Contract.Tipo__c}"/> 
                            <apex:outputField value="{!Contract.agente__c}"/>
                            <apex:outputField value="{!Contract.Status}"/>
                            <apex:outputField value="{!Contract.accordo_prog__c}"/>
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>
                        
                    <apex:pageBlockSection id="section2" columns="2" title="Condizioni Commerciali">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:outputField value="{!Contract.invio_lett_intenti__c}"/>
                            <apex:outputField value="{!Contract.ricez_lettera_intenti__c}" />
                            <apex:outputField value="{!Contract.StartDate}"/> 
                            <apex:outputField value="{!Contract.endContractDate__c}" />
                            <apex:outputField value="{!Contract.discount__c}"/>
                            <apex:outputField value="{!Contract.contract_sign_date__c}"/> 
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>  
                        
                    <apex:pageBlockSection id="section3" columns="2" title="Dati per Accordo Progettazione" 
					rendered="{!Contract.accordo_prog__c=='Si'}">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:inputField value="{!Contract.CreatedById}"/>
                            <apex:inputField value="{!Contract.LastModifiedById}"/>
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>      
                    
                    <apex:pageBlockSection id="section4" columns="2" title="Informazioni sul sistema">
                        <apex:inlineEditSupport event="ondblClick">
                            <apex:inputField value="{!Contract.CreatedById}"/>
                            <apex:inputField value="{!Contract.LastModifiedById}"/>
                        </apex:inlineEditSupport>
                    </apex:pageBlockSection>  
                </apex:actionRegion>
                    
                </apex:pageBlock>
                </apex:inlineEditSupport>
             </apex:form>
  </apex:define>
</apex:page>

try this page code