3

I have created one custom object called Site, and I have created a lookup from Opportunity to that Custom object. Now I can see the opportunity related list in my custom object, there one button called New Opportunity also available. My client wanted me to change the button name and put the Visual force page which I created for Custom object inside that one. I can't change the standard button so I have gone to the Custom button option. I have created a custom button and given the type as List Button and content source as URL and inside the button I have written the below statement. As expected, I can call the visual force page to that button. But the only issue I can not call the custom object field values inside the visual force page. In the below statement I have referred the Visual force page and custom object fields. Please guide me in this issue.

/apex/Convert_site?{!Site__c.Site_Ref_No__c}{!Site__c.Name} {!Site__c.Site_Address__c}{!Site__c.Project_City__c}{!Site__c.State__c}{!Site__c.Post_code__c}{!Site__c.Account__c}{!Site__c.Completion_Date__c}?
2

When calling your custom page you need to correctly format and encode the URL parameters.

/apex/Convert_site?refNo={!URLENCODE(Site__c.Site_Ref_No__c)}&name={!URLENCODE(Site__c.Name)}&address={!URLENCODE(Site__c.Site_Address__c)}&city={!URLENCODE(Site__c.Project_City__c)}&state={!URLENCODE(Site__c.State__c)}&postcode={!URLENCODE(Site__c.Post_code__c)}&account={!URLENCODE(Site__c.Account__c)}&date={!URLENCODE(Site__c.Completion_Date__c)}

Notice how each parameter is separated by an ampersand (&) and prefixed with a key. Also, each parameter is wrapped in a URLENCODE so that special URL characters will be correctly encoded.

Then, in your custom visualforce page controller you can access the parameters passed to the page.

string siteRefNo = ApexPages.CurrentPage().getParameters().get('refNo');

Since the Site custom object already exists it should be sufficient to pass the Id and then run a SOQL query in the page controller to retrieve the required records.

  • Thank you so much for the detailed code Daniel. I will try this and let you know the result. – Arun May 28 '13 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.