function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sales4cesales4ce 

Passing query Parameters from Controller to VF page

Hi,

 

I have created a VF page that has Standard Contoller="Account" and a controller extension.

I have a button called "New Contact" on that page and when clicked should take them to the New Contact creation page with "Account Name" populated in it.

 

This is how the URL would look like:

https://na7.salesforce.com/003/e?retURL=%2F001A00000083F5b&accid=001A00000083F5b

 

The coloured part being the ID of account.

 

For the same to happen from my visualforce page i have created and passed the query parameters, but its not behaving the way it should.

Can anybody help me with where i am going wrong?

 

VF Page:

<apex:page standardController="Account" extensions="contactRelatedList" >
    <apex:form >
        <apex:PageBlock title="Contacts">
            <div style="Position:Relative;Left:400px">
                <apex:CommandButton Value="New Contact" Title="Create a New Contact" action="{!newContact}" /> 
                <apex:CommandButton Value="Merge Contacts" Title="Merge Duplicate Contacts"/>
            </div>
            
        </apex:PageBlock>  
    </apex:form>
</apex:page>

 

Controller Extension:

public class contactRelatedList {
    
    List<Contact> activeContacts=New List<Contact>();
    String AcctId;
    String returnurl;
    public contactRelatedList(ApexPages.StandardController controller) {
         
         AcctId= Apexpages.CurrentPage().getParameters().get('Id'); 
        // returnurl= '%2F'+AcctId+'&accid='+AcctId;
           returnurl=AcctId+'&accid='+AcctId; 
         activeContacts=[Select Name,Title, Email, Phone From Contact Where 
                                                                       AccountId=:Apexpages.CurrentPage().getParameters().get('Id')];
                                                                       

    }
    
    Public List<Contact> getactiveContacts(){
    
        return activeContacts;
    }
    
    Public PageReference newContact(){
        System.Debug('Return URL=='+returnurl);
        PageReference newcontactref=New pageReference('https://na7.salesforce.com/003/e');
        newcontactref.getParameters().Put('retURL',returnurl);
       return newcontactref;
    }

}

 

 

In the debug log i get the value as expected, but when passing it as query parameter i get it this way:

https://na7.salesforce.com/003/e?retURL=001A00000083F5b%26accid%3D001A00000083F5b

 

I see that Characters "&" and "=" are having those values that are coloured in red.

 

Thanks,

Sales4ce

sfdc guy.ax723sfdc guy.ax723

At first glance it looks as though you are asking for the wrong param. You are asking for :

 

AcctId= Apexpages.CurrentPage().getParameters().get('Id');

 

and shoud be asking for:

 

AcctId= Apexpages.CurrentPage().getParameters().get('accid');

 

the 'id' param is not in your query string.

 

sfdc guy

Pradeep_NavatarPradeep_Navatar

Change the characters by ascii value and and set in the URL and get the value in visual force page by using '{!$CurrentPage.parameters.rf}' == 'No'

if your URL look like eg /ui/portal/DisablePortalUserPage/e?save=1&retURL=%2Fapex/HOC__Contact_Overview%3Frf=No