• David Leckenby
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
Is it possible to navigate from a related list on a standard contact page to a visualforce page. For example
User-added image
If I click the highlighted link on this standard opportunity link can I redirect the user to another visualforce page detailpage and NOT the standard opportunity detail page?


 
I have created a visualforce page that displays both opportunity and contact fields that I want users to be able to edit and save. I am using the opporutnity standard controller and added the following extension so as to be able to override (or add to) the standard save functionality with the 'SaveBoth' method (below). I have managed to be able to query the correct contact and populate the contact ID, but upon 'Save' none of the contact fields on the Visualforce page are updating.

Here is the Controller Extention
public with sharing class NewLeadControllerExtension 
{
    ApexPages.StandardController controller;
    public Opportunity oppt {get; set;}
    public Account acct {get; set;}
    public Contact cont {get; set;}

    public NewLeadControllerExtension(ApexPages.StandardController controller)
    {
        this.controller = controller;
        oppt = (Opportunity)controller.getRecord();
        acct = new Account();
        cont = new Contact();
        acct.Name = oppt.Account.Name;
        cont.Id = [SELECT Id FROM Contact WHERE Name =: acct.Name LIMIT 1].Id;
    }
    public String getTitle()
    {
        return 'The Contact ID is '+ cont.Id;
    }
    public PageReference SaveBoth()
   {
        update cont; 
        controller.Save(); 
        return null;
   }
}
Here is my visualforce page
<apex:page standardController="Opportunity" extensions="NewLeadControllerExtension">
   <p>{!title}</p>
   <apex:form >  
   <apex:pageBlock title="New Sales Leads">
   
       <apex:pageBlockButtons location="bottom">
          <apex:commandButton action="{!SaveBoth}" value="Save" rerender="section1"/>
          <apex:commandButton action="{!QuickSave}" value="QuickSave"/>
       </apex:pageBlockButtons>
   
       <apex:pageBlockSection title="Opportunity Fields" columns="2" >
          <apex:repeat value="{!$ObjectType.Opportunity.FieldSets.Opportunity_Fields}" var="field">
             <apex:inputField value="{!Opportunity[field]}"/>  
          </apex:repeat>
          <apex:outputField value="{!Opportunity.Id}"/>     
       </apex:pageBlockSection>
       
       <apex:pageBlockSection title="Contact Fields" columns="2" id="section1">
          <apex:inputField value="{!Opportunity.Account.Id}"/>
          <apex:inputField value="{!Opportunity.Account.Name}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Rating__c}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Name}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Id}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Lead_Source__c}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.MobilePhone}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Email}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Do_you_own_an_investment_property__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Level_of_Investment__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Project_of_Interest__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Life_Cycle_Stage__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Purchase_Type__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.No_of_Bedrooms__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.First_Home_Buyer__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Call_Details__c}"/>  
       </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
       <apex:pageBlock title="Activity Blah">
       <apex:pageBlockSection title="Call and Email Hitory" columns="1" >
             <apex:relatedList subject="{!opportunity.account.contact__r}" list="ActivityHistories" /> 
       </apex:pageBlockSection>
       </apex:pageBlock>
       <apex:pageMessages /> 
</apex:page>
Many thanks for your help

 
I have created a visualforce page that displays both opportunity and contact fields that I want users to be able to edit and save. I am using the opporutnity standard controller and added the following extension so as to be able to override (or add to) the standard save functionality with the 'SaveBoth' method (below). I have managed to be able to query the correct contact and populate the contact ID, but upon 'Save' none of the contact fields on the Visualforce page are updating.
public with sharing class NewLeadControllerExtension 
{
    ApexPages.StandardController controller;
    public Opportunity oppt {get; set;}
    public Account acct {get; set;}
    public Contact cont {get; set;}

    public NewLeadControllerExtension(ApexPages.StandardController controller)
    {
        this.controller = controller;
        oppt = (Opportunity)controller.getRecord();
        acct = new Account();
        cont = new Contact();
        acct.Name = oppt.Account.Name;
        cont.Id = [SELECT Id FROM Contact WHERE Name =: acct.Name LIMIT 1].Id;
    }
    public String getTitle()
    {
        return 'The Contact ID is '+ cont.Id;
    }
    public PageReference SaveBoth()
   {
        update cont; 
        controller.Save(); 
        return null;
   }
}


 
Dear All

I have created a visualforce page that has both opportunity and contact fields that I want users to be able to edit and save. I am using the opporutnity standard controller and added the following extension so as to be able to override (or add to) with the 'SaveBoth' method. I am having trouble populating the contact object with the correct related record data.

I am recieveing the following error:- "Invalid foreign key relationship: Opportunity.AccountId"

I am trying to do the following:- 
1) Declaring the object variables
2) Instantiating the controller
3) Instantiating the objects
4) Trying to set the Id of the contact object to that of the account related to the opporutnity.
5) Invoking the controllers 'Save' Method
6) Inserting (or Update?) the contact object to the database

Any help with my approach is greatly appreciated!
 
public with sharing class NewLeadControllerExtension 
{
    ApexPages.StandardController controller;
    public Opportunity oppt {get; set;}
    public Contact cont {get; set;}

    public NewLeadControllerExtension(ApexPages.StandardController controller)
    {
        this.controller = controller;
        oppt = (Opportunity)controller.getRecord();
        oppt.AccountId.Contact.Id = cont.Id;
    }
    public PageReference SaveBoth()
    {
        controller.Save();
        insert cont; 
        return null;
    }
}

 
I have created a visualforce page that displays both opportunity and contact fields that I want users to be able to edit and save. I am using the opporutnity standard controller and added the following extension so as to be able to override (or add to) the standard save functionality with the 'SaveBoth' method (below). I have managed to be able to query the correct contact and populate the contact ID, but upon 'Save' none of the contact fields on the Visualforce page are updating.

Here is the Controller Extention
public with sharing class NewLeadControllerExtension 
{
    ApexPages.StandardController controller;
    public Opportunity oppt {get; set;}
    public Account acct {get; set;}
    public Contact cont {get; set;}

    public NewLeadControllerExtension(ApexPages.StandardController controller)
    {
        this.controller = controller;
        oppt = (Opportunity)controller.getRecord();
        acct = new Account();
        cont = new Contact();
        acct.Name = oppt.Account.Name;
        cont.Id = [SELECT Id FROM Contact WHERE Name =: acct.Name LIMIT 1].Id;
    }
    public String getTitle()
    {
        return 'The Contact ID is '+ cont.Id;
    }
    public PageReference SaveBoth()
   {
        update cont; 
        controller.Save(); 
        return null;
   }
}
Here is my visualforce page
<apex:page standardController="Opportunity" extensions="NewLeadControllerExtension">
   <p>{!title}</p>
   <apex:form >  
   <apex:pageBlock title="New Sales Leads">
   
       <apex:pageBlockButtons location="bottom">
          <apex:commandButton action="{!SaveBoth}" value="Save" rerender="section1"/>
          <apex:commandButton action="{!QuickSave}" value="QuickSave"/>
       </apex:pageBlockButtons>
   
       <apex:pageBlockSection title="Opportunity Fields" columns="2" >
          <apex:repeat value="{!$ObjectType.Opportunity.FieldSets.Opportunity_Fields}" var="field">
             <apex:inputField value="{!Opportunity[field]}"/>  
          </apex:repeat>
          <apex:outputField value="{!Opportunity.Id}"/>     
       </apex:pageBlockSection>
       
       <apex:pageBlockSection title="Contact Fields" columns="2" id="section1">
          <apex:inputField value="{!Opportunity.Account.Id}"/>
          <apex:inputField value="{!Opportunity.Account.Name}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Rating__c}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Name}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Id}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.Lead_Source__c}"/>
          <apex:inputField value="{!Opportunity.Account.Contact__r.MobilePhone}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Email}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Do_you_own_an_investment_property__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Level_of_Investment__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Project_of_Interest__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Life_Cycle_Stage__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Purchase_Type__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.No_of_Bedrooms__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.First_Home_Buyer__c}"/>
          <apex:outputField value="{!Opportunity.Account.Contact__r.Call_Details__c}"/>  
       </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
       <apex:pageBlock title="Activity Blah">
       <apex:pageBlockSection title="Call and Email Hitory" columns="1" >
             <apex:relatedList subject="{!opportunity.account.contact__r}" list="ActivityHistories" /> 
       </apex:pageBlockSection>
       </apex:pageBlock>
       <apex:pageMessages /> 
</apex:page>
Many thanks for your help

 
I have created a visualforce page that displays both opportunity and contact fields that I want users to be able to edit and save. I am using the opporutnity standard controller and added the following extension so as to be able to override (or add to) the standard save functionality with the 'SaveBoth' method (below). I have managed to be able to query the correct contact and populate the contact ID, but upon 'Save' none of the contact fields on the Visualforce page are updating.
public with sharing class NewLeadControllerExtension 
{
    ApexPages.StandardController controller;
    public Opportunity oppt {get; set;}
    public Account acct {get; set;}
    public Contact cont {get; set;}

    public NewLeadControllerExtension(ApexPages.StandardController controller)
    {
        this.controller = controller;
        oppt = (Opportunity)controller.getRecord();
        acct = new Account();
        cont = new Contact();
        acct.Name = oppt.Account.Name;
        cont.Id = [SELECT Id FROM Contact WHERE Name =: acct.Name LIMIT 1].Id;
    }
    public String getTitle()
    {
        return 'The Contact ID is '+ cont.Id;
    }
    public PageReference SaveBoth()
   {
        update cont; 
        controller.Save(); 
        return null;
   }
}


 
Dear All

I have created a visualforce page that has both opportunity and contact fields that I want users to be able to edit and save. I am using the opporutnity standard controller and added the following extension so as to be able to override (or add to) with the 'SaveBoth' method. I am having trouble populating the contact object with the correct related record data.

I am recieveing the following error:- "Invalid foreign key relationship: Opportunity.AccountId"

I am trying to do the following:- 
1) Declaring the object variables
2) Instantiating the controller
3) Instantiating the objects
4) Trying to set the Id of the contact object to that of the account related to the opporutnity.
5) Invoking the controllers 'Save' Method
6) Inserting (or Update?) the contact object to the database

Any help with my approach is greatly appreciated!
 
public with sharing class NewLeadControllerExtension 
{
    ApexPages.StandardController controller;
    public Opportunity oppt {get; set;}
    public Contact cont {get; set;}

    public NewLeadControllerExtension(ApexPages.StandardController controller)
    {
        this.controller = controller;
        oppt = (Opportunity)controller.getRecord();
        oppt.AccountId.Contact.Id = cont.Id;
    }
    public PageReference SaveBoth()
    {
        controller.Save();
        insert cont; 
        return null;
    }
}