+ Start a Discussion
Dhanamjaya PaidipatDhanamjaya Paidipat 

To Stop loading the standard page

Hi Everyone,
I have created a Visual page on Lead and added on Lead page but if i try to update the fields from visual page after save the page it's loading to Lead page.

Kindly help us to avoid this issue assp.
Thanks in Advance.
Code:
<apex:page sidebar="false" showheader="false" standardController="Lead" action="{!routePage}">
<apex:form >
<apex:outputLabel ><b> #Call: </b></apex:outputLabel>
<apex:outputField value="{!Lead.Call_Number__c}"/>

<apex:outputLabel ><b> #Attempt: </b></apex:outputLabel>
<apex:outputField value="{!Lead.Attempt_Number__c}"/>

<apex:pageBlock >

<apex:pageBlockSection columns="1" title="Patient details" rendered="{!Lead.Country__c== 'India'}">

<apex:outputField value="{!Lead.name}"/>
<apex:outputField value="{!Lead.Phone}"/>

<apex:inlineEditSupport />

</apex:pageBlockSection>

<apex:pageBlockSection title="Patient Consent" rendered="{!Lead.Country__c== 'India'}">

<apex:outputField value="{!Lead.Gendre__c}"/>

<apex:inlineEditSupport />

</apex:pageBlockSection>
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlock>
                
                
           
</apex:form>

 
</apex:page>

Error:
Visual page

 
Best Answer chosen by Dhanamjaya Paidipat
Dhanamjaya PaidipatDhanamjaya Paidipat
thanks a ton

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Dhanamjaya,

Greetings to you!

You are using the standard controller Save, which redirects you to the record view page for the object  This means that you get a standard salesforce page embedded in an iframe within your standard visualforce page.
 
You need to create an extension controller that leaves the user on your Visualforce page after they click Save.

Controller:
public class CreateAccountC {
    
    ApexPages.StandardController stdCtrl;
    public CreateAccountC(ApexPages.StandardController std)
    {
        stdCtrl=std;
    }
    
    public PageReference save()
    {
        stdCtrl.save();
        return null;
    }
}

Add on a page attribute:
<apex:page sidebar="false" showheader="false" standardController="Lead" extensions="CreateAccountC" action="{!routePage}">

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
Dhanamjaya PaidipatDhanamjaya Paidipat
Hi Khan,

Thanks for your support.
I tried this way but if i created a Iam not able to add visual page in my Lead pagelayout.
Can you please help me on this ?
Khan AnasKhan Anas (Salesforce Developers) 
You need to use Lead standardController with extensions, something like this:
 
<apex:page standardController="Lead" extensions="CreateAccountC" action="{!routePage}" sidebar="false" showheader="false">

Regards,
Khan Anas
Dhanamjaya PaidipatDhanamjaya Paidipat
Thank you so much !!
Let me try this and get back to you .
Dhanamjaya PaidipatDhanamjaya Paidipat
thanks a ton
This was selected as the best answer
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

It's my pleasure. I’m glad I was able to help!

Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue. *(If you mark the answer as best answer which helps you to solve the problem, the question is marked as “resolved”)*

Regards,
Khan Anas