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
Art SaberArt Saber 

Question on custom button to fill out fields from multiple pages

I would like to create a button on an opportunity detail page. The buttom will lead to a page to update fields, which the fields are sitting on the opportunity detail page and the account detail page. 

I do not know where to start on this. Help/direction will be much appreciated. 
Best Answer chosen by Art Saber
GarryPGarryP
I would be happy to help. any configuration realted difficulties you can always go thru the Salesforce documenattion. It is awesome peice of work with great step by step examples.
https://help.salesforce.com/articleView?id=salesforce_help_map.htm&type=0

1. apex page that should be created
<pre>
<apex:page standardController="Opportunity" sidebar="true">
  <apex:sectionHeader title="User Edit" subtitle="New User" />
    <!-- Begin Form -->
    <apex:form >
      <apex:pageBlock title="User Informations" mode="edit">
        <apex:pageBlockSection columns="2" showHeader="true" title="Information">
        <!--using syntax as {!OPPORTUNITY.PUT_API_NAme_OF_Editbale_Field} will give editbale 
        fields-->
          <apex:inputField id="firstName" value="{!Opportunity.Name}" required="false" />
          <!--put the field to be updated in this fashion, for details go thru the documentation-->
          <!--apex:inputField allows to see the fields in Edit mode-->
          <!--to get the Account Fields in edit mode you will have to use the API name of Account Object
          Example if website of Account should be edited , check API name of website field and than  use below syntax
          {!Opportunity.Account.Website}
          -->
            <apex:inputField id="lastName" value="{!Opportunity.AccountId}"  required="false" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
            <!-- this button will give you save fucntionality-->
              <apex:commandButton value="Save" action="{!save}" rerender="error"/>
              </apex:pageBlockButtons>
            </apex:pageBlock>
          </apex:form>
        </apex:page>
</pre>

2. Create new button for opportunity.
here is documenttaion from salesforce. it is step by step , should be easy.
Note: You will have to change  the content of URL window as follows -

/PUT_YOUR_VF_PAGE_Name_HERE?id={!Opportunity.Id}

3. Add the Button to layout.

Test it out! this should work.

All Answers

GarryPGarryP
Not sure how good you are at development.But you can start as follows -
1. write VF page that accepts opportunity ID
2. USe standard controller (than only it will be available to use as a button at Opportunity layout) as opportunity and an extension apex class
3. Write logic in apex class (extension) to grab fields of related object in extension
4. Create a custom button and use the VF page created at #1
5. Good to go!

Let me know if you face any challenges.
Art SaberArt Saber
Thank you Girish. I am new to SFDC and my development skills are not even on the radar yet. If it isn't too much trouble could you please elaborate on your direction?

Thank you. 
GarryPGarryP
I would be happy to help. any configuration realted difficulties you can always go thru the Salesforce documenattion. It is awesome peice of work with great step by step examples.
https://help.salesforce.com/articleView?id=salesforce_help_map.htm&type=0

1. apex page that should be created
<pre>
<apex:page standardController="Opportunity" sidebar="true">
  <apex:sectionHeader title="User Edit" subtitle="New User" />
    <!-- Begin Form -->
    <apex:form >
      <apex:pageBlock title="User Informations" mode="edit">
        <apex:pageBlockSection columns="2" showHeader="true" title="Information">
        <!--using syntax as {!OPPORTUNITY.PUT_API_NAme_OF_Editbale_Field} will give editbale 
        fields-->
          <apex:inputField id="firstName" value="{!Opportunity.Name}" required="false" />
          <!--put the field to be updated in this fashion, for details go thru the documentation-->
          <!--apex:inputField allows to see the fields in Edit mode-->
          <!--to get the Account Fields in edit mode you will have to use the API name of Account Object
          Example if website of Account should be edited , check API name of website field and than  use below syntax
          {!Opportunity.Account.Website}
          -->
            <apex:inputField id="lastName" value="{!Opportunity.AccountId}"  required="false" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
            <!-- this button will give you save fucntionality-->
              <apex:commandButton value="Save" action="{!save}" rerender="error"/>
              </apex:pageBlockButtons>
            </apex:pageBlock>
          </apex:form>
        </apex:page>
</pre>

2. Create new button for opportunity.
here is documenttaion from salesforce. it is step by step , should be easy.
Note: You will have to change  the content of URL window as follows -

/PUT_YOUR_VF_PAGE_Name_HERE?id={!Opportunity.Id}

3. Add the Button to layout.

Test it out! this should work.
This was selected as the best answer
Art SaberArt Saber
WOW, thank you so much for the code and directing me to documentation! Due to your code and the documentation I was able to pretty much get it all down besides one thing. Seems like whenever I enter the field name of a custom field I keep getting an error stating Error: Could not resove field [field name] from <apex:inputField> value binding '{!Opportunity.[field name]} in page. I've double checked that the filed name is correct and that I'm not using the api name.

Thank you in advance.
GarryPGarryP
please check if the field name which you are trying to show on the page is a Formula field? or non editable field?
if it is you will have to change the VF page tag from inputField to outPutfield or outputText.
inputField is binded to accept values from the page.
Art SaberArt Saber
I tried outputfield and output text and same error with value binding comes up.

The custom fields are editable and data manually entered but the api for these fields are linked to formula fields. 
GarryPGarryP
i could not see any other reason.
can you send your code and the api name of the field details that you are trying to refer?
Art SaberArt Saber
<apex:page standardcontroller="Opportunity" sidebar="true">
    <apex:form >
      <apex:pageBlock mode="edit">
          <apex:pageBlockSection columns="2" showHeader="true" title="{!opportunity.name}">
              <apex:inputField value="{!Opportunity.Amount}" required="false"/>
              <apex:inputField value="{!Opportunity.LOI_in}" required="false"/>
          </apex:pageBlockSection>
      <apex:pageblock >
      <apex:commandButton value="Save" action="{!save}" rerender="error"/>
      <apex:commandButton value="Cancel" action="{!cancel}" rerender="error"/>
      </apex:pageblock>
      </apex:pageblock>
    </apex:form>
</apex:page>


User-added image
GarryPGarryP
              <apex:inputField value="{!Opportunity.LOI_in}" required="false"/>
you are using wrong API name
correct api name is suffixed with __c
change this as - 
              <apex:inputField value="{!Opportunity.LOI_in__c}" required="false"/>
 
Art SaberArt Saber
Thank you for all your help. When I tried out the api name I did _, not _ _. Its working now. I haven't gotten there yet but will I have issues when I input fields from Account so I can have fields from Account and Opportunity on the same VF page?
GarryPGarryP
Did you spend time reading the solution inlined above?
please see below comments in code provided above

<pre>
 <!--to get the Account Fields in edit mode you will have to use the API name of Account Object
          Example if website of Account should be edited , check API name of website field and than  use below syntax
         {!Opportunity.Account.Website}
         -->
            <apex:inputField id="lastName" value="{!Opportunity.AccountId}"  required="false" />
</pre>
Art SaberArt Saber
Awesome thank you