You need to sign in to do that
Don't have an account?
Help With An Extension
Hello:
I am trying to develop a Visualforce page where I am inseting a new section of a related object into the record if a certain criteria is met.
I have a custom sObject (Zip_Code__C) that is in a Master-Detail with sObject Sites__c where Zip_Code__c is the parent object.
Site__c has multiple record types so I want to break up the related lists into sections based on record type.
The controller I am tyring to write is:
public class MyController { private final Sites__C sites; public MyController() { sites = [SELECT Name, Units__c FROM Sites__c WHERE Zip_Code__c = :ApexPages.currentPage().getParameters().get('id') AND RecordTypeID='012C0000000GEK4']; } public sites__c getsites() { return sites; } public PageReference save() { update sites; return null; } }
By doing this, it would insert a table into the record itself rather than create a related list.
My Visialforce code is:
<apex:page standardController="Zip_Code__c" extensions="MyController"> <!-- the first example, below, demonstrates the use of the pageBlockTable tag to display a mash-up list of Job Application & Candidate information --> <!-- this is important because we did not have to burn custom fields in order to pull in the candidate info for display --> <!-- also notice that the formatting is taken care of for you when using the pageBlockTable tag --> <apex:pageBlock > <apex:pageBlockTable value="{!Zip_Code__c.Sites__r}" var="item"> <apex:column value="{!item.name}"/> <apex:column value="{!item.Units__c}"/> </apex:pageBlockTable> </apex:pageBlock> <!-- the example below demonstrates the use of the dataTable tag to display the same information as the first example above --> <!-- notice that formatting is not handled for you when using the dataTable tag, and we need to explicitly declare column heading labels --> </apex:page>
I am getting error Error: Unknown constructor 'MyController.MyController(ApexPages.StandardController controller).
Thoughts? Suggestions? Help?
Try the following in re: to the orginal query you had
Apex Class :
Visualforce Page :
I am not sure about your VF page in 2nd query - from what I see, using {!Zip_Code__c.Releases__r} would fetch all records. you need to query for the Releases Object in the controller by putting the WHERE clause (as we did for Sites above) and use that in pageblocktable
All Answers
Your constructor in your Extension class should have Apexpages.StandardController as argument. try changing your code
Here in code i made few changes,
1. Removed the Apexpages.currentPage and added the controller.getId() method,
2 .Changing the Sites__c to a List as the query you are trying to run will always return a list but not a single record.
Hello:
I am still having problems with this. Attached is my VF code:
I used the class mentioned above as the extension however it is still pulling back all record types. Any suggestions?
Thanks,
Matt
Yes. you are using Zip_code__c directly from the VF Page in the PageBlockTable, you should use the one from the controller class. In your case try using sites., because that was the list that is retrieved with a WHERE filter.
Kartik:
I'm not sure I understand exactly where you are referencing me to make the change in my VF code. I am sorry I am new to all of this coding. Could you tell me where I need to make the change?
Try the following in re: to the orginal query you had
Apex Class :
Visualforce Page :
I am not sure about your VF page in 2nd query - from what I see, using {!Zip_Code__c.Releases__r} would fetch all records. you need to query for the Releases Object in the controller by putting the WHERE clause (as we did for Sites above) and use that in pageblocktable
Thank you so much for your help. This did it.
Kartik:
Could you attempt to help me with two other components of the Apex Class?
I only want to display records where the Date_of_Last_Resweep is at least 90 days prior. (Example, I would only want records to show in my table where Date_of_Last_Resweep is September 12, 2012 or prior).
Also, when the class executes, I want them sorted by Current_Penetration__c from lowest to highest.
Any suggestions? I cannot quite figure this out.
Thanks in advance!
Matt
in your SOQL where clause just add " AND Date_of_Last_Resweep < LAST_90_DAYS ORDER BY Current_Penetration__c".
Kartik:
Can I bug you again if you don't mind?
I have the following:
sObject Resweep__c is the Parent in a Lookup Relationship with Site__c
sObject Site__c is the Parent in a Lookup Relationship with Video_Qualified_Address__c
sObject Video_Qualified_Address__c is the parent in a Lookup relationship with Subscriber__c
I need to write VF code to pull Video_Qualified_Address__c and Subscriber__c fields into a pageblocktable where Resweep__c.Site__c = Video_Qualified_Address__c.Site__c
I tried to use the code from your previous reply as a guide but I am having trouble with the condition that Site__c on the Resweep__c record = Site__c on the Video_Qualified_Address__c record.
What do I need to change?
Thanks a million for all your help.
Matt