You need to sign in to do that
Don't have an account?
![uHaveOptions uHaveOptions](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Using ApexPages.currentPage().getParameters().get('id') with a custom visualforce page
I've been having some problems with replacing a Standard controller view with a Visualforce page following this: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_tabs.htm
The problem is, it's breaking a lot of my apex classes. For example, anything that uses:
Which will throw this error:
Here is one example of a code that is breaking:
Are there any alternatives to
The problem is, it's breaking a lot of my apex classes. For example, anything that uses:
ApexPages.currentPage().getParameters().get('id')
Which will throw this error:
Id value is not valid for the Property__c standard controllerIs there another way to get record ids using visualforce pages? We use these frequently
Here is one example of a code that is breaking:
public class ControllerCreateProposalView { public Id lId; public String convertedId; public ControllerCreateProposalView(ApexPages.StandardController stdController){ lId = ApexPages.CurrentPage().getParameters().get('id'); System.Debug('#######leadId:' + lId); } public PageReference convert(){ Property__c l = [SELECT Id, name, Primary_Contact__c, Primary_Contact__r.id,Store_Number__c, Last_Sale_Date__c, Square_Footage__c, Last_Sale_Price__c, Anchor_GLA__c, CAP_Rate__c, Year_Built__c, Lot__c, Year_Renovated__c, Occupancy__c, Zoning__c, External_ID_APN__c, Number_of_Buildings__c, Number_of_Retail_Units__c, Loan_Balance__c, Maturity_Date__c, Interest_Rate__c, Term__c, Original_Lease_Term__c, Options__c, Term_Remaining_on_Lease__c, Gross_Leasable_Area__c, Type_of_Ownership__c, Parking__c, Parking_Ratio__c, Lease_Type__c, Date_Reported__c, Loan_Amount__c, Loan_Type_bcc__c, LTV__c, Lender__c, Lender_Type__c, Amortization__c, Recourse__c, Current_Interest_Rate__c, Payment__c, Prepayment__c, Proposal_date__c FROM Property__c WHERE Id=:lId LIMIT 1]; Proposal__c c=new Proposal__c(Name=l.Name, Property__c=l.Id, Client__c=l.Primary_Contact__c, Square_Footage__c=l.Square_Footage__c, CAP_Rate__c=l.CAP_Rate__c, Lot__c=l.Lot__c, Loan_Balance__c=l.Loan_Balance__c, Maturity_Date__c=l.Maturity_Date__c, Term__c=l.Term__c, Original_Lease_Term__c=l.Original_Lease_Term__c, Options__c=l.Options__c, Term_Remaining_on_Lease__c=l.Term_Remaining_on_Lease__c, Anchor_GLA__c=l.Anchor_GLA__c, Occupancy__c=l.Occupancy__c, Number_of_Buildings__c=l.Number_of_Buildings__c, Number_of_Retail_Units__c=l.Number_of_Retail_Units__c, Gross_Leasable_Area__c=l.Gross_Leasable_Area__c, Type_of_Ownership__c=l.Type_of_Ownership__c, Parking__c=l.Parking__c,Parking_Ratio__c=l.Parking_Ratio__c, Year_Built__c=l.Year_Built__c, Lease_Type__c=l.Lease_Type__c, Date_Reported__c=l.Date_Reported__c, Loan_Amount__c=l.Loan_Amount__c, Loan_Type__c=l.Loan_Type_bcc__c, LTV__c=l.LTV__c, Lender__c=l.Lender__c, Interest_Rate__c=l.Interest_Rate__c, Lender_Type__c=l.Lender_Type__c, Amortization__c=l.Amortization__c, Recourse__c=l.Recourse__c, Current_Interest_Rate__c=l.Current_Interest_Rate__c, Payment__c=l.Payment__c, Prepayment__c=l.Prepayment__c); insert c; l.Sales_Status__c = 'Proposal'; l.Proposal_Date__c=Date.today(); update l; convertedId = c.Id; String cID=l.Primary_Contact__r.id; System.Debug('<>PROPOSAL<> :' + l ); System.Debug('<>CEYEDEE<><>cID<><>CEYEDEE<> :' + cID ); //update contact stage List<Contact> contacts=[SELECT Id, Sales_Status__c FROM Contact WHERE id=:cID]; System.Debug('<>LIST<><>contacts<><>LIST<> :' + contacts ); if(contacts.size()>0){ for(Contact i: contacts) { if(i.Sales_Status__c=='Unconfirmed'||i.Sales_Status__c==NULL){ i.Sales_Status__c='Proposal'; update i; } } } String sServerName = ApexPages.currentPage().getHeaders().get('Host'); sServerName = 'https://'+sServerName+'/'; System.Debug('#######sServerName :' + sServerName ); String editName='/e?retURL=%2F'+convertedId; PageReference retPage = new PageReference(sServerName + convertedId+editName); System.Debug('#######retPage :' + retPage ); retPage.setRedirect(true); return retPage; } public PageReference back(){ String sServerName = ApexPages.currentPage().getHeaders().get('Host'); sServerName = 'https://'+sServerName+'/'; System.Debug('#######sServerName :' + sServerName ); PageReference retPage = new PageReference(sServerName + lId); System.Debug('#######retPage :' + retPage ); retPage.setRedirect(true); return retPage; } }
Are there any alternatives to
ApexPages.currentPage().getParameters().get('id')
Please find the below code:
This will work if your Standard Controller for the VF page is Property__c.
Please do let me know if it helps you.
Regards,
Mahesh
What is your Visualforce Page.
It should be:
Please paste your VF page also here.
Regards,
Mahesh
Hi Jon,
How are you testing this page?
It should be from Property__c details page. But not sure how you are testing it.
Also what is the value you are getting in the debug for below message:
System.Debug('#######Prop Id:' + prop.Id);
Regards,
Mahesh
Added a screenshot here: tiikoni.com/tis/view/?id=7dee2ed
Please try this option:
Here the Source is Visualforce Page and Content is yout actual page.
Please do let me know if it helps you.
Regards,
Mahesh
is null
What about the other controller extension, can you do the samething in that controller also and see the debug.
Regards,
Mahesh
I tested the code from below URL and it is displaying both controllers properly.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm
And tested it with below URL:
https://c.na2.visual.force.com/apex/AccountExtentionVF?Id=0014000000HJXxF
Regards,
Mahesh
?
All the input fields needs to change from
<apex:inputField value="{!Property__c.Tenant_Sub_Type__c}" id="Property"/>
to
<apex:inputField value="{!prop.Tenant_Sub_Type__c}" id="Property"/>
This way we are able to capture and store the Property__c record information into a member variable.
prop is member variable of any of the extension controller.
Regards,
Mahesh
I found a way to get around this problem. The visualforce page was just a "Are you sure you want to do this yes/no"? page, so I simply replaced this with a javascript pop up dialog box that does the same thing.
But, my underlying problem still remains. When I use a visualforce page instead of a standard page, {!sObject.id} no longer works on a custom button. Here's another example of this problem.
I have a "Log a Call" button, which used to work. Here's a screenshot of it:
http://www.tiikoni.com/tis/view/?id=01a901c
As you can see, the URL is /00T/e?who_id={!Contact.Id}&followup=1&tsk5=Call&retURL=%2F{!Contact.Id}
This button still works, but it does not return a "whoid" or an id for "retURL", these are both null. So after the user saves the task, when they save the task, they end up back on the home page.
I tried replacing it with this code:
http://www.tiikoni.com/tis/view/?id=e2b7549
/00T/e?who_id={!Contact.Id}&followup=1&tsk5=Call&retURL=apex/ContactTabs?id={!Contact.Id}
This uses the URL for the new visualforcepage. But I when I use this version of the button, it gives me an error:
Id value is not valid for the Contact standard controller
The same thing happened to my other custom button on the Property__c object. When I used my custom visualforce page {!Property__c.id} returned null.
So, how can I fix the problem of {!sObject.id} always returning null?
Please provide me the printscreen of you button so that it will be easy to troubleshoot.
Regards,
Mahesh
You can use below URL:
Other parameters you can pass based on your requirement.
I already tested and it is working fine.
Regards,
Mahesh
Tried it and its the same behavior as before. It works, but after the user saves it, they are redirected to the home page. And the contact id is blank in the URL.
http://www.tiikoni.com/tis/view/?id=9692314