+ Start a Discussion
jtwoods4jtwoods4 

cannot Pass ID to APEX Page using URLFOR

I am a .NET Developer and this is my first week developing salesforce applications. I was asked to make a custom salesforce APEX page that performs a "callout" to an external webservice. I was able to do this. However, I am not able to pass in the Account ID from the account page to the new APEX page.

 

I modiied the account view page to include a command button that redirects to my new APEX page. See code here

 

<apex:page standardController="Account" tabStyle="Account">
     <apex:pageBlock >
            <apex:form >             
                 <apex:commandButton action="{!URLFOR("/apex/RECALLDEV2",Account.id)}" value="TTM Revenue" /> 
            </apex:form>        
     </apex:pageBlock>
     <apex:detail subject="{!Account.Id}"/>              
</apex:page>

 

And here is my custom APEX page and Controller that handles the URLFOR redirect

 

 

public with sharing class RECALLDEV2Manager 
{
   
    private final List<Account> account;

    public RECALLDEV2Manager (ApexPages.StandardController controller) 
    {
        account = [SELECT Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public string getHelloWorld() 
    {
        RECALLDEV2.WebService2Soap service = new RECALLDEV2.WebService2Soap();
        string responseFromService = service.HelloWorld();
        
        return responseFromService;
    }

}

 

Here is the Page, I am simply trying to access the account object I populated in the controller and write the company name to the page but it does not appear

 

<apex:page standardController="Account" extensions="RECALLDEV2Manager">
    <h1>Test Page</h1>
    <apex:pageBlock >

        <apex:form >
            <apex:outputLabel value="{!HelloWorld}" />
            <p>You are viewing the {!account.name} account.</p>

        </apex:form>

    </apex:pageBlock>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
rohitsfdcrohitsfdc

if you are getting missing '(' error, please your command button with following code

<apex:commandButton action="{!urlfor('/apex/recalldev2?id=' +account.id)}" value="TTM Revenue" />

All Answers

rohitsfdcrohitsfdc

hi,

Change your href tag

 

<apex:commandButton action="{!URLFOR("/apex/recalldev2?id=" :Account.id)}" value="TTM Revenue" />

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

<apex:page standardController="Account" tabStyle="Account">

     <apex:pageBlock >

            <apex:form >             

                <apex:commandButton action="{!URLFOR('/apex/RECALLDEV2?id='+account.id)}" value="TTM Revenue" />

            </apex:form>       

     </apex:pageBlock>

     <apex:detail subject="{!Account.Id}"/>     

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

jtwoods4jtwoods4

The syntax in both of the replys is incorrect. Any more ideas?

rohitsfdcrohitsfdc

Both the syntaxs are right.

Are you giving id of account while opening your first vf page??

for ex

https://c.ap1.visual.force.com/apex/1stvfpage?id=00190000003OHIS  in my case.

 

Because, if you not giving id in the address bar of browser account.id wont work.

 

Please take a look into following link.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_query_params_getting.htm

 

 

jtwoods4jtwoods4

Yes i have the ID. Thanks for the links. However I pasted the commandbutton code above and got an apex syntax error on both statements.

rohitsfdcrohitsfdc

if you are getting missing '(' error, please your command button with following code

<apex:commandButton action="{!urlfor('/apex/recalldev2?id=' +account.id)}" value="TTM Revenue" />

This was selected as the best answer
Mayank_JoshiMayank_Joshi

Hey Rohit ,

 

I hope ,you will reply on it : 

 

Below page is just to autopopulate Name value . After Saving, we are conctenating Name field (using workflows). As , Name is Required field for this we have to autopopulate as generalValue (this will ovveride after saving) .

 

I have created below Page and it works fine . But when I override this page on Standard New Button( with VF option under  setup)  .This page will reload recursively without returning anything . You can try to overide Standard New Button on Account (just change Program__c to Account) .

 

Do we have any other way to stop it to load continously itself. 

:

 

<apex:page standardController="Program__c" extensions="naa" action="/a05/e?Name=AutoGeneratedName" />

 

 

 

Public class naa
 {
   Public Program__c a = new Program__c();
   Public naa(ApexPages.StandardController controller)
   {   } 
   
  }

 

Thanks in Advance ,