You need to sign in to do that
Don't have an account?
Shwetal Desai
how to set Master Record Id in VF page of Detail Object?
I have two custom objects with master-detail relationships.
Detail custom object's New button has overrided with the Visual force page.
now, I want to access Master's Record Id to set in Detail's Field in "Save" method in EXTENSION class. This method is to insert the detail record .
How can i Do this?
Thanks in Advance.
Shwetal
You'll need to use something like:
master = [select id from Master__c where id = :ApexPages.currentPage().getParameters().get(detail.id + '_lkid')]; if (detail.Master__c == null) { detail.Master__c = master.Id; }
}
Message Edited by Luke@TWS on 10-14-2008 08:47 AM
Thank you for the solution...
I have a custom object called Project (the 1), and a custom object called Phase (the many), with a lookup relationship to Project (projects have multiple phases). It's a lookup because the phase has a 1-many relationship with another object - financial note - and so on. I'm also using a custom page to override the New page for my "many" object.
So I tried rewriting your code to this:
I wasn't sure a good way to debug, so I rewrote it like this:
and tried displaying the various properties on the page, but it appears my currentpageID field is not getting set. I tried looking up some of the functions in the documentation and couldn't find anything (they still list $CurrentPage). I'd really want to find some good documentation on the Parameters usage, but no luck there.
Any ideas?
Thanks for any help you can spare.
and then tried to display it as this in my page:
Because you're asking me that, I'm guessing that SF doesn't actually generate the new record ID until insertion time?
Based on a dump of the getParameters() passed into the controller, I think I can get away with just looking for a key value with suffix of "_lkid". But how is this issue commonly dealt with?
Thanks for your help.
But I didn't put the ID (nor the relationship ID) on the page, though. I'd think I wouldn't want to put those fields on the page as standard input fields. Maybe make them hidden?
and also as outputFields, and neither seem to be populated. BTW, I did this in my extension class (for the time being):
where domtemp__c is a table with the String2__c string field. I'm basically just trying to capture information so I can see it b/c I don't know a better way to debug this (is there a better way?). I've attached these methods (writeParams and writeIDs) to buttons on the page, and push them to insert the values into the table. I'm still getting blank values in domtemp__c for both the parent ID and the child ID. So I'm still doing something wrong.
How have you got your objects and vf pages setup?
I have a VF page which has custom related lists. I have setup the object with an overriden New action so it goes to my new page when I click new on the related list. This takes me to my vf page with standard controller. I have a hidden field for the master record which I set in the extension. Can't see any reason why yours would not work if it is setup in the same way.
I'm overriding the "New" SB&L action with my custom page. The custom page has my controller extension.
I did a lookup relationship because my CDEPhase__c object will be a parent to another object, and the way I understand it (and through trying to configure it master/detail originally), I can't use master/detail chained like that.
I am now using the following as my relationship ID assignment. I'm not loving it, and am worried about how the parameters keys work (what is the lkid anyway? Could there be more than one? Is there documentation somewhere?), but this works for me: