You need to sign in to do that
Don't have an account?

Save Button's Method Code which when clicked Saves the object and redirects to the parent Object
Hi,
Am new to salesforce, I had customized my org with my requirements, But am facing some problem:
I have a Custom JunctionObject__c which has 2 fileds CustomField1__c master-detail relation to CustomObject1__c and Similarly CustomField2__c master-detail relation to CustomObject2__c.
I had Customized the new edit page to my own VF page i.e. VF1 n used StandardController=”JunctionObject__c ”.
And overriden the "New" button of JunctionObject__c to VF1.
So when we go from CustomObject1__c (PARENT) record we can see the related block JunctionObject__c , NOW when I click the "NEW" button the VF! appears Good. and I insert the data and click Save Button am going to detail page of JunctionObject__c,
But I need to be redirected to the CustomObject1__c detail page of that id.
Here's below is the VF1 page :
<apex:page standardController="JunctionObject__c" extensions="testController"> <apex:sectionHeader title="JunctionObject Edit" subtitle="New JunctionObject" /> <apex:form id="myForm"> <apex:pageBlock title="JunctionObject Edit" mode="edit"> <Apex:pageBlockButtons > <apex:commandButton action="{!save}" value="save"/> <apex:commandButton action="{!cancel}" value="cancel"/> </Apex:pageBlockButtons> <apex:pageBlockSection title="JunctionObject Information" columns="1"> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="CusomField1"/> <apex:inputField value="{!var.CustomObject1__c}" /> </apex:pageBlockSectionItem> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="CusomField2"/> <apex:inputField value="{!var.CustomObject2__c}" /> </apex:pageBlockSectionItem> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
And my TestController is as Follows::
public class testController { public JunctionObject__c var {get;set;} public testController(ApexPages.StandardController controller) { var= new JunctionObject__c(); } }
I didn't write any code for save Method, Now Please suggest the code for Save Method which saves the object and redirects it to the parent CustomObject1__c.
I.e. a Save button when clicked saves the inputvalues to the JunctionObject and Redirectes straight away to the previous CustomObject1 from where it came.
Would be very helpful, if provided the code.
Thankyou.
PageReference viewtPage = new ApexPages.StandardController([SELECT Id FROM CustomObject1__c WHERE Id =:var.CustomObject1__c ]).view();
viewtPage.setRedirect(true);
return viewtPage;
All Answers
Well the code should be very straight forward.
To save you will have to do a DML update/upsert/insert
so
PageReference viewtPage = new ApexPages.StandardController([SELECT Id FROM CustomObject1__c WHERE Id =:var.CustomObject1__c ]).view();
viewtPage.setRedirect(true);
return viewtPage;
Hi,
Add the parameter saveURL in the URL and pass the CustomObject1 or CustomObject2 record ID.
This will take you to the respective parent page.
Regards,
Arun.
Thanks for your Reply, But with the my Intial Code am falling to Pre-Populate the value of Parent i.e. CustomObject1__c's Customfield1__c in the JunctionObject__c.
So I had Treid with my new code for Same Requirement , Plesae check the following Code:
VF page :
and the Controller is:
Please help me in Save Method i.e. Code which saves the object and redirects it to the parent CustomObject1__c.
i.e. a Save button when clicked saves the inputvalues to the JunctionObject and Redirectes straight away to the previous CustomObject1 from where it came.
-ThankYou.