0

I have Vf pages on Opportunity and contact.i have continue button to redirect opportunity vf to contact vf. i want to auto-populate fields from opportunity vf page to contact vf page. i'm using one controller when i use controller in contact vf page it shoes error . new to salesforce, any suggestions? (ignore other methods ) Contact owner and account name should auto-populate

<apex:page standardController="Opportunity" extensions="opportunityOrderDetail" >
<apex:form >
  <apex:messages />
    <apex:pageBlock title="Opportunity details"  >

    <apex:pageBlockSection title="Opportnuity Infromation" >
        <apex:inputField value="{! Opportunity.OwnerId }" />
        <apex:inputField value="{! Opportunity.Name }"/>
        <apex:inputField value="{! Opportunity.Account.Name }"/>

        <apex:inputCheckbox value="{!Opportunity.Order_Details__c}" >
            <apex:actionSupport event="onchange" action="{!check}" reRender="AddInfoSection"  />  
        </apex:inputCheckbox>
    </apex:pageBlockSection> 
    <apex:outputPanel id="wrapperPannel" layout="none"  >  
     <apex:pageBlockSection title="Additional Information" id="AddInfoSection" rendered="{!showInfo}">
        <apex:inputField value="{! Opportunity.OrderNumber__c }" /> 
        <apex:inputField value="{! Opportunity.MainCompetitors__c }"   /> 
        <apex:inputField value="{! Opportunity.DeliveryInstallationStatus__c }"  />
        <apex:inputField value="{! Opportunity.TrackingNumber__c }"   /> 
     </apex:pageBlockSection>
    </apex:outputPanel> 

    <apex:pageBlockSection title="Description Information">
    <apex:inputCheckbox value="{!Opportunity.ReadOnly__c}">
        <apex:actionSupport event="onchange" action="{!ReadOnlyCheckBox}" reRender="ReadOnlySection"  />
    </apex:inputCheckbox> <br/>
    <apex:inputTextarea value="{! Opportunity.Description }" id="ReadOnlySection" disabled="{!Readval}"/> <br/>
    <apex:inputField value="{! Opportunity.Reason_for_Rejection__c}"/> 

    </apex:pageBlockSection>
    <apex:pageBlockButtons >

        <apex:commandButton action="{!save}" value="save"/>
        <apex:commandButton action="{!cancel}" value="cancel"/>
      <apex:commandButton action="{!continueButton}" value="Continue"/>
    </apex:pageBlockButtons>
    </apex:pageBlock>


opportunityOrderDetail Controller

public with sharing class  opportunityOrderDetail{
public Opportunity oppty{get;set;}
public Boolean showInfo{get;set;}
public Boolean Readval{get;set;}
public Contact con{get;set;}
private ApexPages.StandardController stdCtrl;
public  opportunityOrderDetail(ApexPages.StandardController std){
    showInfo=false;
    Readval=false;
    stdCtrl=std;
    Opportunity oppty=(Opportunity)stdCtrl.getRecord(); 
    }   
public pagereference  autopop(){
    Contact cont=(Contact)stdCtrl.getRecord();
    cont.AccountId=[SELECT ID,Name FROM Opportunity where Id=:Oppty.AccountId];
    return null;

}
public pagereference check(){  
    if(showInfo ==true){ 
       showInfo=false; 
     } 
     else{ 
         showInfo= true; 
     } 

    return null; 
 } 
public pagereference ReadOnlyCheckBox(){
   if (Readval==true){
            Readval=false;
            }else{Readval=true;
                }
            return null;
            }           

public pagereference BackButton(){
    return Page.OppView;
 }
public pagereference continueButton(){
   return Page.RedirectDetailPage;

}

}

Contact Vf page

<apex:page standardController="Contact"  extensions="opportunityOrderDetail" 
 action="{!autopop}" >
<apex:form >
<apex:pageBlock title="Contact Details ">
     <apex:pageBlockSection>
        <apex:inputField value="{!Contact.OwnerId}" />
        <apex:inputField value="{!Contact.Account.Name}" /> 

        <apex:inputField value="{!Contact.FirstName}" />
        <apex:inputField value="{!Contact.LastName}" />






    <apex:pageBlockButtons >
 <apex:commandButton action="{!BackButton}" value="Back"/>  
        <apex:commandButton action="{!save}" value="save"/>
        <apex:commandButton action="{!cancel}" value="cancel"/>

    </apex:pageBlockButtons>
  </apex:pageBlock>


</apex:form>  

0

When your redirecting to contact VF page, standardController is look for Id of the contact. You have set contact id to page reference.

Make sure cont is not null before redirecting page.

public pagereference continueButton(){
   PageReference pageRef = new  Page.RedirectDetailPage;
   pageRef.setRedirect(true);
   pageRef.getParameters().put('id',cont.id);
   return pageRef;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.