+ Start a Discussion
KS KumaarKS Kumaar 

how to open detailed edit page of a record using button click in visual force

I have a Vf page which display account object records. In this vf page each and every record have a button called Edit. If we click on Edit button it should be take us to detailed edit page respected record. For more clearance see my pictures which i uploded. 
User-added image
User-added image

To achive this process, I have developed following VF page.

<apex:page Controller="Redirect_Main2" action="{!Redirect_Main}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a" >
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column id="two">
                    <apex:commandButton value=" Edit " onclick="window.open('/{!a.id}')" reRender="two"/>
<!--/e?retURL=%2F{!a.id}&_CONFIRMATIONTOKEN=VmpFPSxNakF4Tmkwd055MHlPVlF3T1Rvek5qb3dPQzQ0TnpaYSxvTFl3eklmdmNBcjl6RlVDeDRWUnBtLE9XWTJNbU01&common.udd.actions.ActionsUtilORIG_URI=%2F{!a.id}%2Fe')" reRender="two"/>
   -->             </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller:
public class Redirect_Main2 {

   public List<Account> accs { get; set; }
    public PageReference Redirect_Main(){
        accs = [select id,name,phone,Industry from account];       
        return null;
     }
}
 


But this is taking me to detailed page of the record but not edit page. Please tell me neccessary actions which i need to take.

Thanking you
KS Kumaar

Best Answer chosen by KS Kumaar
Virendra ChouhanVirendra Chouhan
Hi KS Kumaar,

After saving the record it'll redirect you to home page because there is no return url in current URL.
So for redirecting it to detail page you must have to set record Id on retURL attribute. 
try this one:
<apex:commandButton value=" Edit " onclick="window.open('/{!a.id}/e?retURL={!a.id}')" reRender="two"/>

 

All Answers

Navee RahulNavee Rahul
Hello Ks Kumar,

you can also use like below to achive the functionality
 
<apex:outputLink value="{!URLFOR($Action.Account.Edit,a.Id,['retURL'=cancelDestination, 'saveURL'=saveDestination],true)}">
                <apex:outputText value="Edit"/>
            </apex:outputLink>
Let me know if it helps.

Thanks
D Naveen rahul.
 
Virendra ChouhanVirendra Chouhan
Hi KS Kumaar,

It need a little change on your CommandButton :
<apex:commandButton value=" Edit " onclick="window.open('/{!a.id}/e')" reRender="two"/>
use the above code it'll work.

Thanks
Viru
 
KS KumaarKS Kumaar
Hi Virendra Chouhan, 
Its working good. But once i save the record, page is redirecting to some another page. 
can not going to detailed page.
Virendra ChouhanVirendra Chouhan
Hi KS Kumaar,

After saving the record it'll redirect you to home page because there is no return url in current URL.
So for redirecting it to detail page you must have to set record Id on retURL attribute. 
try this one:
<apex:commandButton value=" Edit " onclick="window.open('/{!a.id}/e?retURL={!a.id}')" reRender="two"/>

 
This was selected as the best answer
KS KumaarKS Kumaar
Now its working good Virendra Chouhan. Thanks a lot Chouhan.
 
KS KumaarKS Kumaar

Hi Virendra Chouhan,

I got a doubt. Could you please explain it.
As you said i change modification in commandbutton by using return url like and it is working good.

<apex:commandButton value=" Edit " onclick="window.open('/{!a.id}/e?retURL={!a.id}')" reRender="two"/>

But i found another return which is just used %2F like below and and it is also working good.

<apex:commandButton value=" Edit " onclick="window.open('/{!a.id}/e?retURL=%2F{!a.id}')" reRender="two"/>

So, what my doubt is what is the differnce between both URLs even they are giving same result rather than changing URLs while getting saved?
sales@myvarmasales@myvarma
instead of record page how to get small window to edit values in that record
 
SFDC TortoiseSFDC Tortoise
If i want to create same operation for delete link, When i click on del link it will open record and contain a delete button for deleting record. Plz help me 
Abhishek joshi 75Abhishek joshi 75
IF my Edit page is Custom Page then How to do??