+ Start a Discussion
AncaDAncaD 

Populate a field on a page for a custom object with the value of the field from another page

Hi,

 

I have two custom objects and need to populate a field on the page for one of them with the value of the field from the other page (when I navigate from one page to another). I created a PageReference object that I use to redirect to the second page. The redirect works, but I can't populate the field on the second page with the value from the first page. The problem that I'm having is that the URL requires the ID of the field (I've tried using the API name of the field but didn't work) and I can't find a way to retrieve it. I don't want to hardcode the ID of the field, because it will change when I move the code to another environment.

 

I used Schema.DescribeSObjectResult to get the object ID for the second page, and tried to use the Schema.DescribeFieldResult to get the field ID, but couldn't get it to work.

 

Any suggestions will be greatly appreciated.

 

Thank you

mtbclimbermtbclimber
Are you trying to default values in the standard edit page or a form in a visualforce page?
AncaDAncaD
In the standard edit page for the custom object.
mtbclimbermtbclimber
There's no supported way to do this today.
AncaDAncaD

I forgot to mention that I have a Visualforce page in between the two standard edit pages for the custom objects - the flow is like this:

 

first standard view page -> visualforce page (through a custom list button) -> second standard edit page

 

the field that I want to populate on the second standard edit page is from the first standard view page

mtbclimbermtbclimber
One thing you could do is update the fields in the visualforce page before the redirect but if the user cancels the operation or doesn't otherwise complete the process the fields will still have been updated.
AncaDAncaD

I use the VF page as part of a wizard-like functionality. The users don't do any updates there - they do it on the standard page to where I do the redirect.

 

 

This is how my URL for the redirect looks like:

 

.../a0b/e?FieldID=A-0006439&Id=a06R00000063m5H&retURL=a06R00000063m5H 

 

I was able to get the object id (a0b), the value for the FieldID (A-0006439) and the value for the Id and retURL (a06R00000063m5H) programmatically, but not the FieldID

 

 

It seems strange to me that you can't get the id of a field from a standard page.

BrianWKBrianWK

Since you're the standard Edit page...

 

I've Passed values to the edit page field through the URL. I've gotten the parameters from the URL by going to the edit page and viewing the source...

 

I've found this works to code in a sandbox environments and still works after I deploy to a sandbox.

 

So if my Field parameters was 00N300000018dBy the URL would look like this:

 

.../a0b/e?FieldID=A-0006439&Id=a06R00000063m5H&retURL=a06R00000063m5H&00N300000018dBy=MyValue

 

mtbclimbermtbclimber
And just to make sure it's clear to anyone reading this post - this is not supported and may change or otherwise cease to work this way in a future release.  Anytime you view source on a standard page to do something like this you are exposing your implementation to regressions.  Proceed with caution.
BrianWKBrianWK

That's good to know Andrew.

 

Do you see anything on the Roadmap that may suggest that may "break" in the near future? We've used this functionality in a number of places -- including custom buttons to ease documentation. For example, automatically filling in the related to fields based on the parent (example custom object links both Case and Account. Created from the case populates the case, but must manually enter Account).

 

It'll be good to have an idea if there's anything coming that will change or cease this functionality to work so I can prepare users.

 

Thanks!