I have two custom objects, Category and Case, I set category as parent. Column Category_ID in category is referenced by custom object Case. I executed two queries in developer console
SELECT Category_ID__c,id, Name FROM Category__c
SELECT Category_ID__c,id, Name FROM Case__c
and I found out the value of Category_ID in Case was like 'a0D'F000001MmjUae' and 'a0D'F000001MmjUde',yet in Category it's '0' and '1'.
VisualPage
<apex:outputLabel value="Category" />
<apex:selectList value="{!categoryType}" size="1">
<apex:selectOptions value="{!items}"/>
</apex:selectList>
<apex:outputLabel value="Case" />
<apex:selectList value="{!caseId}" size="1">
<apex:selectOptions value="{!items2}"/>
</apex:selectList>
//From here is Controller
public String categoryType{set;get;}
public List<SelectOption> getItems(){
List<selectoption> mlst = new List<selectoption>();
for(VirtualCaseCategory__c m: [SELECT Category_ID__c, Name FROM VirtualCaseCategory__c]){
mlst.add(new selectoption(m.Id,m.Name));
}
return mlst;
}
public List<SelectOption> getItems2(){
List<selectoption> mlst = new List<selectoption>();
for(VirtualCaseCases__c m: [SELECT Category_ID__c, Name FROM VirtualCaseCases__c WHERE Category_ID__c =:categoryType]){
mlst.add(new selectoption(m.Id,m.Name));
}
return mlst;
}
I want to get different Case selectList based on selected Category_ID value.
Anyone can tell me why? Because I want to run some queries based on the same Category_ID value.
I think you're not adding Category_Id__c in selectList using for loop.
for(VirtualCaseCategory__c m: [SELECT Category_ID__c, Name FROM VirtualCaseCategory__c]){
// insert Category_ID__c in the select option
mlst.add(new selectoption(m.Category_ID__c,m.Name));
}
Same is the case with other for loop
for(VirtualCaseCases__c m: [SELECT Category_ID__c, Name FROM VirtualCaseCases__c WHERE Category_ID__c =:categoryType]){
// Same here as well
mlst.add(new selectoption(m.Category_ID__c,m.Name));
}
Related
I have a visualforce page that has a picklist called Topic and sometimes I will need to select one of the picklist options upon page load (meaning the Topic will be passed on from another page and will need to be selected upon loading the page for the first time). I'm not sure how to do this? I'm posting part of the Visualforce page that handles topic selection and the Controller code that below. Any help would be appreciated.Thanks.
Visualforce page:
<!---------------------------------- Select Topic ----------------------------------------------------->
<apex:pageblockSection title="Select the Topic" >
<apex:selectList value="{!topic}" size="1">
<apex:outputlabel for="Topic" value="Pick a Topic :" ></apex:outputlabel>
<apex:selectOptions id="topic" value="{!Topics}"/>
<apex:actionSupport action="{!populateParameters}" reRender="parametersSection,querySection" event="onchange"/>
</apex:selectList>
</apex:pageblockSection>
<!---------------------------------- End of Select Topic ---------------------------->
<!---------------------------------- Parameters for Topic ----------------------------------------------------->
<apex:pageblockSection id="parametersSection" title="Input Parameters">
<apex:repeat value="{!topicpParamWrapperList}" var="params">
<apex:outputPanel >
<apex:outputlabel value="{!params.parameter.Name}" ></apex:outputlabel>
<apex:inputfield value="{!params.parameter.inputValue__c}" rendered="{!params.renderAsText}">
<apex:actionsupport action="{!placeValuesInQuery}" reRender="querySection,splunUrlLink" event="onchange"/>
</apex:inputfield>
<apex:inputfield value="{!params.parameter.DateTimeValueHolder__c}" rendered="{!params.renderAsDate}">
<apex:actionsupport action="{!placeValuesInQuery}" reRender="querySection,splunUrlLink" event="onchange"/>
</apex:inputfield>
</apex:outputPanel>
</apex:repeat>
</apex:pageblockSection>
<!---------------------------------- End of Parameters for Topic ----------------------------------------------------->
Apex Controller
public List < topicpParamWrapper > topicpParamWrapperList {
get;
set;
} {
topicpParamWrapperList = new List < topicpParamWrapper >();
}
public void populateParameters()
{
if(!topicpParamWrapperList.isEmpty())
{
topicpParamWrapperList.clear();
}
if(topic!='' && topic!=Null)
{
for(Query_Parameter__c qParam :[select id, Parameters__r.Variable_Name__c, Parameters__r.Type__c,Parameters__r.Name from Query_Parameter__c where Topics__c=:topic])
{
Parameters__c param = new Parameters__c();
param.Name =qParam.Parameters__r.Name ;
param.type__c = qParam.Parameters__r.type__c;
param.Variable_Name__c=qParam.Parameters__r.Variable_Name__c;
topicpParamWrapperList.add(new topicpParamWrapper(param));
}
getQueryToRun();
}
}
public void getqueryToRun(){
if(mapTopics.containsKey(topic))
{
this.queryToRun =mapTopics.get(topic).query__c;
this.queryMain=mapTopics.get(topic).query__c;
}
}
public List < topicpParamWrapper > paramList {
get;
set;
} {
paramList = new List <topicpParamWrapper>();
}
All you really have to do is to set the topic to some initial value in the constructor (the special function that has name identical to class' name). You set it to some value and then it'll be rendered properly in visualforce (assuming same value is one of the selectable options!).
You have omitted the constructor or <apex:page> tag so we don't know how you're navigating to that page. But probably easiest for you would be to pass the topic in the URL. So if you access the page like that:
/apex/MyPage?topic=Something, something
then in the constructor you could do this:
topic = ApexPages.currentPage().getParameters().get('topic');
(the name of the URL parameter doesn't have to be same as the variable name but it makes sense to have them at least similar)
You can read more about getParameters()
If there is risk that your topic will contain &, spaces etc you probably should URLENCODE it when building the link.
im tring to display records in question__c object along with fields in object as radio button. but im not able to get radio button value. getting only radio button without name.
im new to salesforce.if this is very basic question pls excuse me.
<apex:page standardController="question__c" extensions="GetQuestionList" >
<apex:form >
<apex:repeat value="{!que}" var="a">
<apex:pageBlock >
<apex:pageBlockSection columns="1">
{!a.Quiz_question__c} {!a.id} <br/>
<apex:selectRadio value="{!selectedAns}" >
<apex:selectOption itemValue="{!opt3}" itemLabel="{!a.option_3__c}"/>
<apex:selectOption itemValue="{!opt4}" itemLabel="{!a.option_4__c}"/>
</apex:selectRadio>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:repeat>
</apex:form>
</apex:page>
____mycontroller is
public class GetQuestionList {
question__c q1;
public List<question__c> que{set;}
public List<question__c> getque(){
List<question__C> que= new List<question__c>();
for(question__C q:[select Quiz_question__c,id from question__c]){
que.add(q);
system.debug(que);
}
system.debug(que);
return que;
}
public String selectedAns{get;set;}
public String opt2{get;set;}
public String opt4{get;set;}
public String opt3{get;set;}
public GetQuestionList(ApexPages.StandardController controller) {
}
}
The reason you have no label is because the value field on the <apex:selectRadio> is a String variable, rather than a field. If you want to add a label, there is a label attribute on that visualforce component you can use.
If you want the label to be dynamically shown based on an actual field's label in the data model, you need to set the value field to that field. An example of that would be if you had an Answer__c field on the Question__c object.
<apex:selectRadio value="{!a.Question__r.Answer__c}">
<apex:selectOption itemValue="{!opt3}" itemLabel="{!a.option_3__c}"/>
<apex:selectOption itemValue="{!opt4}" itemLabel="{!a.option_4__c}"/>
</apex:selectRadio>
That value field would use the label assigned to that field in the object model by default.
I want to display the AggregateResult on my Visualforce page but it is generating the following error " Invalid field Email for SObject AggregateResult"
Below is my code:
public with sharing class searchDuplicate {
public AggregateResult[] con{get;set;}
public searchDuplicate()
{
find();
}
public void find(){
con = [select Email from Contact group by Email having count(Email) > 1];
System.debug(con);
}
}
Below is my visualforce page code:
<apex:page controller="searchDuplicate">
<apex:pageBlock title="Searching for Duplicate Contacts Record">
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:dataTable value="{!con}" var="c" border="2" cellspacing="5" cellpadding="5">
<apex:column headerValue="Email" value="{!c['Email']}" />
</apex:dataTable>
</apex:pageBlock>
</apex:page>
kindly Make a correction if possible
public with sharing class searchDuplicate {
public list <con> conList{get;set;}
public class con{
public string Email {get;set;}
public con( string email){
this.Email = email;
}
}
public searchDuplicate()
{
find();
}
public void find(){
conList = new list <con>();
for( AggregateResult ar : [select Email from Contact group by Email having count(Email) > 1];){ conList.add(new con(string.valueOf(ar.get('Email')))) }
}
}
Aggregate results (and their fields/columns) come as generic Objects, not sObjects. Therefore there's no obj.get('somefieldname') you can call on them.
Your best option might be to make a helper class that has String email; Integer count; fields and loop through the query results populating a list of objects of this helper class.
You could also use Map<String, Integer> but that'd come to VF as not sorted alphabetically.
See https://salesforce.stackexchange.com/questions/7412/count-a-grouped-by-soql if you need a code sample.
Although the other answers are correct in solving your problem, what you have is actually a bug in SalesForce.
The way to resolve this without creating a custom object is to separate the into two - The "headerValue" and "value" both being set cause this error.
You want to change it to this:
<apex:dataTable value="{!con}" var="c" border="2" cellspacing="5" cellpadding="5">
<apex:column headerValue="Email" >
<apex:outputText>{!c['Email']}</apex:outputText>
</apex:column>
</apex:dataTable>
Thanks,
Michael
Hi I am getting a headache with the visualforce repeater control:
<apex:repeat value="{!productDetails}" var="o">
<apex:pageBlockSectionItem >
<apex:outputText style="label" value="Name:"></apex:outputText>
<apex:outputLabel value="{!o.name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputText value="{!o.ProductCode}"/>
<apex:outputText value="{!o.Family}" />
</apex:pageblockSection>
<apex:pageBlockSection>
<apex:outputText style="label" value="Quantity:"> </apex:outputText>
<apex:inputText value="{!theList}"/>
</apex:pageblockSection>
</apex:repeat>
What I am trying to do, is for each record in the product details list, generate a text box. This text box is bound to another field (theList.quantity). But I am finding that when I change the value in the last text box it sets the quantity in all the text boxes(obviously as they are bound to the same field).
So my question is whats the best way to have each textbox that is generated in the repeater have its own parameter value?
Or am I using the repeater in the wrong way?
EDIT(clarification):
For each product detail record(What I am iterating through) I want to have a textbox where a user can enter the quantity of products. The value of this textbox is unrelated to the product detail records.
My question is how can I generate unique parameters for each iteration of the textbox? Hopefully that makes sense.
Cheers
You need to use the var in the <apex:repeat> for each element in the productDetails list. For example:
<apex:repeat value="{!productDetails}" var="productDetail">
<apex:pageBlockSection>
<apex:outputText style="label" value="Quantity:"> </apex:outputText>
<apex:inputText value="{!productDetail.quantity}"/>
</apex:pageblockSection>
</apex:repeat>
That will set the the quantity property of each productDetail.
If you're really iterating over a parent of the productDetail in this example, then you'll need to change your controller to create a parent for each and then iterate over that. I'll write the example code as if you're iterating over a list of potential orders.
In your controller, you'll need to create an order for each of the products. I'm not sure if the parent is an SObject or a custom class, but I'll write the example as if it was a custom class.
public class Order {
public Order(ProductDetail productDetail) {
this.productDetail = productDetail;
}
public ProductDetail productDetail;
public Integer quantity;
}
// I assume you've already implemented this getter or are setting it some other way.
public ProductDetail[] productDetails {
get {
if (productDetails == null) {
productDetails = ...;
}
return productDetails;
}
set;
}
public Order[] orders {
get {
if (orders == null) {
orders = new Order[]{};
for (ProductDetail productDetail: productDetails) {
orders.add(new Order(productDetail);
}
}
return orders;
}
set;
}
Now, in your VisualForce page you can iterate over the Order list and have the user set the quantity.
<apex:repeat value="{!orders}" var="order">
...
<apex:outputtext style="label" value="Name:"></apex:outputText>
<apex:outputLabel value="{!order.productDetail.name}" />
...
<apex:inputText value="{!order.quantity}"/>
....
</apex:repeat>
Back in your controller, only save the orders that have a quantity of more than zero (or whatever other criteria you have in mind).
The easiest way to do this is to add a custom field to the object you're repeating through. However, I understand there are cases where that's not desirable.
You probably could use a custom Apex object (not custom Salesforce object) for this. You can do this by adding a nested class within your Controller or Extension.
For example:
public class MyClass
{
public class MyProductDetail
{
public string Name {get;set;}
public string Family {get;set;}
public string ProductCode {get;set;}
public integer Quantity {get;set;} // theList
}
public List<MyProductDetail> MyProductDetails {get;set;}
}
You would need to loop through all of your Product detail records (returned from SOQL), and add them to the MyProductDetails list. Once you have that, though, you can use a Visualforce Repeater to display each of them them and save the inputted quantity data for each record.
<apex:repeat value="{!MyProductDetails}" var="o">
<apex:pageBlockSectionItem >
<apex:outputText style="label" value="Name:"></apex:outputText>
<apex:outputLabel value="{!o.Name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputText value="{!o.ProductCode}"/>
<apex:outputText value="{!o.Family}" />
</apex:pageblockSection>
<apex:pageBlockSection>
<apex:outputText style="label" value="Quantity:"> </apex:outputText>
<apex:inputText value="{!o.Quantity}"/>
</apex:pageblockSection>
</apex:repeat>
Hope that helps!
Okay, I've been banging my head trying to figure out how to get around this issue without writing unnecessary code.
I have the following Visualforce code that is causing a error when saving:
<select id="rec_count">
<apex:repeat value="{!pg}" var="selpg">
<option {!IF(selpg.value = selectedpgtxt, 'selected','')} value="{!selpg.value}" >
{!selpg.value}
</option>
</apex:repeat>
</select>
The error is:
Error: Element type "option" must be followed by either attribute specifications, ">" or "/>".
Apparently the visual force parser is upset about a option tag not having a attribute for the {!IF(selpg.value = selectedpgtxt, 'selected','')}.
I have tried the equivalent of:
<option selected="" value="1">1</option>
<option selected="selected" value="2">2</option>
However browser considers all of the options selected doing this.
Unless this is considered unnecessary code, the following seems pretty straightforward to me.
Visualforce:
<apex:selectList value="{!theSelection}">
<apex:selectOptions value="{!theList}"/>
</apex:selectList>
Apex:
// Top of class
public List<SelectOption> theList {get; private set;}
public String theSelection {get; set;}
// In constructor
this.theList = new List<SelectOption>();
this.theList.add(new SelectOption('1', 'First Option'));
this.theList.add(new SelectOption('2', 'Second Option'));
// Now for the default
this.theSelection = '1';