0

Edit for clarification: There is a detail button with a link to the VF Page. It is to my understanding (but I could be reversed in concept -- that would definitely changed things...) that a line such as

<apex:inputField value="{!siteContactItem.FirstName}">

Will look to the controller for siteContactItem.FirstName and fill it as such. Because of this, in the controller, I'm looking to assign the default value as something to give to the VF page.

In this specific VF Page, I want the auto-filled information to be that of the Account on which the button was clicked. The button is "Renew Contract", and I want it to automatically fill with the current account/contract/contact... info, and allow the user to edit if necessary before saving.


I thought this might pull the current record, and I was confused when it was pulling only some info, not finding other info, and the info displayed was incorrect. According to the info it did pull, I identified that it is in fact getting the current user signed in.

My purposes of my apex class is to bring up a builder with the current account, related contracts, contacts, etc. already filled in, and I can't seem to figure out how to pull that. Suggestions?

I tried replacing 'id' with 'account', but I got Index Out of Bounds which suggests that the query using it...

        ID currentRecordId  = ApexPages.CurrentPage().getparameters().get('account');
    List<Account> accountItems = [SELECT Id, Phone, BillingState, BillingCity, BillingCountry, BillingStreet,
                                  Fax, Website, Name from Account
                                  where Id = :currentRecordId limit 1];

... didn't pull anything successfully.

  • what exactly are you passing into the page in the URL string? account= should be a value starting with 001 of length 15/18 characters – cropredy Jul 26 '16 at 14:54
  • I'm not sure what you're asking. I'm not passing anything explicitly/literally. I'm not giving it an exact ID. I want it to take the current one each time...sorry if I'm missing the mark of your question, maybe I'm confused. – Natalie Spatharakis Jul 26 '16 at 14:56
  • Presumably this is a VF page, the URL to the page would look something like \apex\myVfPage?account=someAcctId – cropredy Jul 26 '16 at 14:57
  • Nope, I'm doing this in the controller, to set the values in the VF Page according to the current account. – Natalie Spatharakis Jul 26 '16 at 14:58
  • 1
    Natalie -- that's the point - what is the current account? Something has to tell the page what is the current account. If your VF page is inline to a standard detail page, then the current account comes from the controller extension's getId() method. If the VF page is standalone, then the ID has to come from the URL. Rather than continue this in comment thread, post more context by using edit - like the VF page, how it is invoked, and rest of the controller – cropredy Jul 26 '16 at 15:02
1

First principles here

Use Case 1 If the VF page is invoked from a button on a standard detail page for object Foo and controller needs the Foo's ID ...

Then, the ID of Foo available to the controller is discoverable via

ApexPages.StandardController ctlr;
public MyController (ApexPages.StandardController ctlr) { // constructor
  this.ctlr = ctlr; 
}

// .... in some property or method 
ID fooId = this.ctlr.getId();

Use Case 2 If the VF page is invoked from a detail page button on Bar and the controller needs access to Foo, then the definition of the button needs to be a URL (not a VF page) with form like:

/apex/thePage?id={!Bar__c.id}&fooid={!Bar__c.Foo__c}

and the controller code looks like:

ApexPages.StandardController ctlr;
public MyController (ApexPages.StandardController ctlr) { // constructor
  this.ctlr = ctlr; 
}

// .... in some property or method 
ID fooId = ApexPages.currentPage().getParameters().get('fooid');

or, better still, use a VF page for Bar for the button

and the controller code looks like:

ApexPages.StandardController ctlr;
Bar__c  bar;
public MyController (ApexPages.StandardController ctlr) { // constructor
  this.ctlr = ctlr;
  this.bar  = (Bar__c) ctlr.getRecord(); 
}

// .... in some property or method 
ID fooId = this.bar.Foo__c; // assumes Foo__c is somewhere in the VF markup
                            // otherwise controller won't have implicit access

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.