You need to sign in to do that
Don't have an account?
Netmaster
URL redirection after saving
Hello,
I want to redirect my page after saving to the details page just created, but I have an error :
public class insererEnfants{ public List<Enfants__c> accts {get; set;} public insererEnfants(ApexPages.StandardController controller){ accts = new List<Enfants__c>(); accts.add(new Enfants__c()); } public void addrow(){ accts.add(new Enfants__c()); } public PageReference save(){ insert accts; PageReference acctPage = new ApexPages.StandardController(accts).view(); acctPage.setRedirect(true); return acctPage; } }
Here is the error :
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Enfants__c> at line 19 column 45
Can you help me, please ?
In the example below, I've assumed the parent sobject is 'Parent__c', and the master/detail relationship in Enfants__c is called 'Parent__c' and is populated. You'll need to change the object/field names as appropriate:
essentially you create a record of the appropriate type, with the id set to the parent record id and then use that to construct the standardcontroller instance.
All Answers
You are trying to create a standard controller with a list of Enfants__c, but the standard controller needs a single record.
thaks for you answer, I want to redirect my page after saving to a custom object record witch is the parent (master relationship) of Enfants__c
How can I do this, please ?
In the example below, I've assumed the parent sobject is 'Parent__c', and the master/detail relationship in Enfants__c is called 'Parent__c' and is populated. You'll need to change the object/field names as appropriate:
essentially you create a record of the appropriate type, with the id set to the parent record id and then use that to construct the standardcontroller instance.
That's fine, thanks a lot, it works !!
I have an other question if you accept, I want to insert the value of the master relationship field automaticlly, and if possible I hide it.
This is my VF page :
Do you know the parent record id in the controller? If you do, I'd just iterate the accts before saving and set the field at that point. You can then simply remove the inputfield.
I removed the inputField "Parent__c" and I obtained this error
Hence my question do you know the parent id server side - if you don't, you'll have to get it from the user. If you do, you'll have to iterate the accts in the save method and fill in that field for each one of them.
Yes, the situation is that from parent I clic a buttom "new" witch take me to the child object (the custom page above), I this page I insert the parent manually (inputField), I want to insert it automaticlly because it is the same parent all time. I hope that is more clear and thaks for your help.
You should be able to pass the id of the parent on the URL if this is a custom button.
Yes, it is a custom buttom, I want to pass the parent name to insert it in this field
So you should be able to change that custom button to pass the id of the record that is currently being displayed on the URL. Your controller can then pick this up.