0

I'm having a bit of an issue where I can't figure out how to auto-populate some fields on a custom VF page that I made. The page is linked from a button that is found on an Orders object and should ideally auto-populate its fields using some of the fields on the Orders record that its linked from. I've already tried using URL hacking on the custom button, but I haven't had any luck. Here's my VF page:

<apex:page standardController="Payee__c">
  <apex:form >
    <apex:pageBlock title="Add Additional Payee Information" mode="save">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="Additional Payee" columns="1">
        <apex:inputField value="{!Payee__c.Order__c}"/>
        <apex:inputField value="{!Payee__c.Payee_Type__c}"/>
        <apex:inputField value="{!Payee__c.Agency__c}"/>
        <apex:inputField value="{!Payee__c.Agent__c}"/>
        <apex:inputField value="{!Payee__c.Additional_Agency_Rate__c}"/>
        <apex:inputField value="{!Payee__c.Rate_Based_On__c}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

So the "Order", "Agency", and "Agent" fields are all lookups. The "Payee Type" and "Rate Based On" fields are picklists. And the "Additional Agency Rate" is a standard text input field. Again, I've already tried using URL hacking, just trying to populate the "Order" field to try to test it out but I haven't had any luck with that. I'm going to try to write an extension for the VF page, so I'll let you know how that goes. If anyone knows how to handle this issue, it would be greatly appreciated! Thanks!

  • 1
    An extension is usually going to be your best bet, especially if you're looking to pass some items within your parameters via a custom button. With extension, you can actually grab the information and assign a value to it. – Jason Hardy Aug 11 '15 at 16:12
  • That's what I figured. I'm going to try to get this extension written and then I'll post what I've got. – Matt Mc Aug 11 '15 at 16:14
  • Take a look at:salesforce.stackexchange.com/questions/6000/… – Jason Hardy Aug 11 '15 at 16:17
0

Alright, I finished the extension and it works. Thanks to Jason Hardy for suggesting the extension! Here it is:

    public class CreateAdditionalPayeeExtension {
    Payee__c payee {get;set;}

    //constructor
    public CreateAdditionalPayeeExtension(ApexPages.StandardController stdController){
        payee = (Payee__c)stdController.getRecord();
        payee.Order__c = ApexPages.currentPage().getParameters().get('ordId');
    }

    public PageReference save(){
        insert payee;
        return null;
    }
}

(You can ignore the save function in the extension; I'm just trying to now make a save button that overrides the standard one on my VF page so that it can redirect to a specific page.) So after I made this, I used it to auto-fill the "Order" lookup field on the VF page (I decided to leave the rest blank). Here's the VF page:

    <apex:page standardController="Payee__c" extensions="CreateAdditionalPayeeExtension">
  <apex:form >
    <apex:pageBlock title="Add Additional Payee Information" mode="save">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="Additional Payee" columns="1">
        <apex:inputField value="{!Payee__c.Order__c}"/>
        <apex:inputField value="{!Payee__c.Payee_Type__c}"/>
        <apex:inputField value="{!Payee__c.Agency__c}"/>
        <apex:inputField value="{!Payee__c.Agent__c}"/>
        <apex:inputField value="{!Payee__c.Additional_Agency_Rate__c}"/>
        <apex:inputField value="{!Payee__c.Rate_Based_On__c}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

So, as you can see, nothing changed on the VF page from before besides the extension at the top, BUT along with the button URL that is on the Order object that links to the page (/apex/Create_Additional_Payee?ordId={!Order.Id}), the extension works to override the

            <apex:inputField value="{!Payee__c.Order__c}"/>

line and when the button is clicked on the Order object, the lookup field is successfully pre-populated, but still able to be changed to something else if the user so desires.

Sorry for the long and convoluted explanation, but that's pretty much the order in which I figured it out so I don't know a better way to explain it. I hope this helps anyone that has the same problem!

  • Are you still a member here? It looks like you haven't logged in for well over a year. Can you accept this answer if it's how you solved your problem? – Adrian Larson Feb 17 '17 at 3:03

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.