You need to sign in to do that
Don't have an account?
RaviKumar
how to navigate from visualforce page button to custom object edit
I have VF page.In that page having one button called "Insert".
My requiement is
"when that "insert" button clicked it should redirect to Custom Object's edit page"
How can i acheive it.
My requiement is
"when that "insert" button clicked it should redirect to Custom Object's edit page"
How can i acheive it.
As per your requirment its very easy to redirect to edit page i.e.
1.The Method in which you are writing insert statement must be Pagereference kind of method like Public Pagereference insertmethod()
2. redirect it like to edit page like i have considered case pagereference pr=new pagereference('/'+5009000000MX0AX);
3.In place of Hard code pass the id which you are variable which you are inserting like insert case;
case.id
4.So it makes every thing dynamic and use return pr(object of pagereference);
Please mark as KUDOs if you satisfy the requirement or reply me with more clear requirment.
Thanks
Srinivas
you can either use javascript in your VF page and redirect the url to the edit page of the record
or if the Insert button is calling any controller action button, then you can set the Pagereference in the controller action to redirect..
either way, the URL you need will be like '/YourRecordId/e'
YourRecordId -> the record id which you want to show in edit mode
e -> edit mode
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm
Partial return URL will look something like: '/' + 'recordID' + '/e'
Let me explain my requirement clearly,
In my VF page haing a button called "NewHostel".
Now , when i clicked on that "NewHostel" button it should able to redirect and allow to enter a new record values into that Custom Object "Hostel".
Image 1
Image 2
In the above Image1 , If i click "NEW Hostel" then Image 2 i.e.., a new recordshould able to insert into that Hostel object.
I have written the below code in the button action method
Hostels__c host;
PageReference hstPage = new ApexPages.StandardController().edit();
return hstPage;
It's not working to my requirement.
Plz give me suggestions.
Can You call inserted record id like this to get edit landing page..
public PageReference save() {
insert opp;
PageReference ref= new PageReference('/'+opp.id);
ref.setredirect(true);
return ref;
}
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlockButtons>
Please let me know if this helps you..
Thank You
I've tried the code you sent.It's showing the detail page of the inserted record.
One clarification for you "The intention for NewHostel button is to open a edit page for Hostels object, there i'm going to insert the new record"
I think you got my requirement.If you need any clarification plz let me know, because i've been trying this for 2 days.
Once again thanks for your reply@dev_sfdct
Use case was to click on the command button on a visualforce page and then open it in edit mode.
This is almost same technique as using a Custom button on a custom or standard object that calls a web services class but insteand of calling the class directly create a javascript function on the VF page that calls the webservices method from the controller and takes me to the edit page. I havent fould a way to eliminate not to use the apex controller.
Code are as follows
In Visualforce page :
-------------------------------
<apex:includeScript value="/support/console/32.0/integration.js"/>
<apex:includeScript value="/soap/ajax/29.0/connection.js" />
<apex:includeScript value="/soap/ajax/29.0/apex.js" />
<apex:includeScript value="/support/console/35.0/integration.js" />
<a class="linkButton" href="javascript:editSuccess('{!Success__c.Id}');">
<button class="slds-button slds-button--brand slds-m-top--medium" type="button">Edit Record</button>
</a>
JavaScript in Visuaforce Page:
------------------------------------------
function editSuccess(val){
var runCreateSuccess;
var runErrorHandling;
var editMode = "/e?retURL=%2F";
var sid = '{!GETSESSIONID()}';
var server = "https://"+window.location.host+"/services/Soap/u/26.0";
sforce.connection.init(sid, server);
runCreateSuccess = sforce.apex.execute("createSuccess","autoEditSuccess",{successId : val});
window.location.reload(runCreateSuccess);
window.open(runCreateSuccess+editMode+runCreateSuccess);
}
Method in Controller
---------------------------
webservice static String autoEditSuccess(Id successId){
String strSuccessecord;
List<Success__c> lstSuccessRecord = [Select Id FROM Success__c where id =:successId];
strSuccessecord = String.valueOf( new PageReference('/'+lstSuccessRecord.get(0).Id).getUrl());
return strSuccessecord;
}