function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
betterbhushanbetterbhushan 

Viewing Column content in column body.

I have this specific problem where I have two Objects 1) Keyword__c and 2) Account. They have master-detail relationship. Now I want to create a table where I want to display each value from Keyword__c in one column and count of Account for that from Master-detail relationship in other column. I tried something like below but I haven't been successful.

 

My Visualforce page has 

 

<apex:pageBlockTable title="Results" value="{!AllKeyword}" var="k">
<apex:column value="{!k.kw__c}" headerValue="Keywords" />
<apex:column headerValue="Count" value="{!KeywordCount}">
<apex:param name="kw" value="{!k.kw__c}"/>
</apex:column>
</apex:pageBlockTable>

  but it says 

 

Error: You may specify either a ''value'' attribute or a body for the column component, but not both	

  

and controller has 

 

public Integer getKeywordCount() {
  Integer cnt;
  String keyID;
  String kw = ApexPages.currentPage().getParameters().get('kw');  
   keyID = [Select Id from Keyword__c where kw__c = kw];  
   cnt = [Select count() FROM KeywordAccountAssociation__c Where Keyword__c = keyID];
  return cnt;
  }

 

but it says 

 

Error: companyDashboard Compile Error: unexpected token: 'kw'

 

Appreciate any help.

Best Answer chosen by Admin (Salesforce Developers) 
SidzSidz

betterbhushan wrote:

If there is any other way from which  I could determine the count for that specific keyword I don't need to pass param. But if not then I do need to pass param


Since the Account ->Keword__c is a master detail relationship create a roll up summary field (count) on account which rolls up the total no of keywords for each account.

you can have the vf code like this to display all the keywords and also the count for each of them

am going with the assumption that the roll up summary field on account is (api name) rollupsummaryfield__c and the relationship name for the master detail relationship is keywords.

 

<apex:page standardController="Account" recordSetVar="accounts">
<apex:repeat title="Results" value="{!accounts}" var="acc">
<apex:pageblocktable value="{!acc.keywords}" var="keyword" title="{!acc.Name}({!acc.rollUpSummaryField__c})">
 <apex:pageblocktable>
<apex:column value="{!keyword.Name}" />
</apex:pageblocktable>
</apex:repeat>
</apex:page>

 

This piece of code should loop through all accounts and display the accountName (count of no of keywords) and list out the keywords for that account.

 

hope this helps.

(please do not forget to mark the answer as accepted solution if it works)

 

Thanks,

Sidz

All Answers

nickwick76nickwick76

The param tag can only be a child of the following attributes:

  • <apex:actionFunction>
  • <apex:actionSupport>
  • <apex:commandButton>
  • <apex:commandLink>
  • <apex:outputLink>
  • <apex:outputText>
  • <flow:interview>

What do you want to do with the param? Do you want to send a value to the controller?

 

If you remove the param tag it should work. You could do like this:

<apex:column headervalue="Count">{!}KeywordCount}</apex:column>

 

If you want to keep the param for a good reason you should enclose it in any of the above attributes which in turn can be enclosed.

 

Regarding the extension class error. By doing this:

String kw = ApexPages.currentPage().getParameters().get('kw')

you are saying that there exists a querystring attribute 'kw' that you are getting the value of. 

Then when you are using it in the SOQL query you have to add ':' to reference it properly, like this.

[Select Id from Keyword__c where kw__c = :kw];

 

HTH Niklas

betterbhushanbetterbhushan

If there is any other way from which  I could determine the count for that specific keyword I don't need to pass param. But if not then I do need to pass param

nickwick76nickwick76

Ok, need to understand better to be able to help.

So Keyword__c is detail to Account.

On a VF-page you want to display the keywords on an account in one column and the count of what in the other column?

/ N 

SidzSidz

betterbhushan wrote:

If there is any other way from which  I could determine the count for that specific keyword I don't need to pass param. But if not then I do need to pass param


Since the Account ->Keword__c is a master detail relationship create a roll up summary field (count) on account which rolls up the total no of keywords for each account.

you can have the vf code like this to display all the keywords and also the count for each of them

am going with the assumption that the roll up summary field on account is (api name) rollupsummaryfield__c and the relationship name for the master detail relationship is keywords.

 

<apex:page standardController="Account" recordSetVar="accounts">
<apex:repeat title="Results" value="{!accounts}" var="acc">
<apex:pageblocktable value="{!acc.keywords}" var="keyword" title="{!acc.Name}({!acc.rollUpSummaryField__c})">
 <apex:pageblocktable>
<apex:column value="{!keyword.Name}" />
</apex:pageblocktable>
</apex:repeat>
</apex:page>

 

This piece of code should loop through all accounts and display the accountName (count of no of keywords) and list out the keywords for that account.

 

hope this helps.

(please do not forget to mark the answer as accepted solution if it works)

 

Thanks,

Sidz

This was selected as the best answer
betterbhushanbetterbhushan

Actually its the opposit. I need number of account for particulat keyword.  Master-detail object name is KeywordAccountAssociation__c. Is it possible to create Rollup summary on custom object?

nickwick76nickwick76

But if the account is master, then a keyword record can only have one account. An account on the other hand can have many keywords. 

betterbhushanbetterbhushan

isn't there many-to-many relationship? In my case a keyword can have many account and an account can have many keyword.

nickwick76nickwick76

If you have a master-detail relationship between account and keyword where account is master. Then the account can have many keywords. A keyword can only have one master account though. 

 

If you want to have a many-to-many relationship you will have to create a junction object between these objects.

 

See more here -> http://www.salesforce.com/us/developer/docs/api/Content/relationships_among_objects.htm

betterbhushanbetterbhushan

Yes I followed those steps only.. created a new object KeywordAccountAssociation__c. They have two fields Account and Keyword to store each one's id.