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
Supper_KentSupper_Kent 

Apex:vote

Does anybody know how to use the Apex:vote component?
bmabma

The Visualforce Developer's Guide has the attributes and description listed.

 

The objectId must be the Id of an object that can be vote on.

Supper_KentSupper_Kent

Sure, that is the only information i can get for this component. And i tried adding some Id of object, Even though my profile is admin, it popped out a message saying insufficient privileges. Is there any set up need to be done? And what kind of object can be voted? Thanks.

bmabma
I know Ideas object can be voted for sure. Not sure about the others.
adam_purkissadam_purkiss

>I know Ideas object can be voted for sure.

 

Based on the sparse documentation available, I'd guess this was true as well.  However, this functionality is not working at all.  I've been hacking at this for days and have come to two conclusions.  For one, it's not possible (or completely obscured from the programmer) to programatically place a vote on an idea using an insert into the vote object.  Required parentId fields that don't exist cause this to break.  Here's the code:

 

 

Vote v = new Vote(ParentId = ideaId, Type = 'Up');
insert v;

 

 

 

and here's the error:

 

 

System.DmlException: Insert failed.  First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ParentId, Value]: [ParentId, Value]

 

 

 

So then, I tried hacking through the <apex:vote.../> control with another brick wall.  The best I can do so far is cause a vote to go through but it redirects to an error page with this error:

 

 

Field $StandardLabel.voteButton.promoted does not exist. Check spelling.

 

 

 

The code I'm using that generates this error is simple, where ideaid is the Id of a single, valid, votable Idea.  Here's the Visualforce code:

 

<apex:vote id="thevote" objectId="{!ideaid}"/>

 

 

I'm also trying to get info through the standard SF support channel and will post any findings but if anyone has even a suggestion here it would be greatly appreciated!!

 

Thanks in advance!

Adam Purkiss

Staff Engineer - Marketo

Jair ZhengJair Zheng

If you got the following error,

 

Field $StandardLabel.voteButton.promoted does not exist. Check spelling.

 You need to set the "rerender"  of the <apex:vote /> tag. 

 

<apex:vote objectId="{!idea.id}" rerender="form"/>

 

The soap api that gives the follwing objects can be setted to the ParentId of vote:

  • Idea
  • Article
  • Question
  • Reply
  • Solution
Andrei KuznetsovAndrei Kuznetsov
You can use this component in Ideas customized with Idea Themes, as an example. Your users will vote on Ideas. You need to link each vote component to actual object withing a table, something like this:

<apex:outputPanel rendered="{!($CurrentPage.parameters.sort != 'comments')}" id="ideaOutput">
<apex:panelGrid columns="3" cellspacing="10" columnClasses="columnTop">
<apex:vote objectId="{!ideadata.Id}" id="vte" />
<apex:image style="border:2px solid #335CAD;" url="{!ideadata.CreatorSmallPhotoUrl}" height="40px" width="40px"/>
<apex:panelGroup >
<ideas:detailoutputLink styleClass="ideaTitle" style="color:#335CAD;" ideaId="{!ideadata.Id}" page="ViewPage">{!ideadata.Title}</ideas:detailoutputLink>
&nbsp;
<apex:outputText style="background-color:#FFFF94;font-size:12px;font-weight:bold;" value=" {!ideadata.Status} " rendered="{!ideadata.Status != ''}"/>
<br />
<span style="color:#990000; font-weight:bold; font-size:10px;">
<apex:outputText value="{!$Label.Posted_by}: "/>
<apex:outputLink style="text-decoration:none;" value="/apex/IdeaProfilePage?c={!currentZone}&u={!ideadata.CreatedBy.Id}&sort=ideas">{!ideadata.CreatedBy.CommunityNickname}</apex:outputLink>
<apex:outputText value="{!IF(ideadata.Categories != '',' -- ','')}" />
<apex:outputText value="{!SUBSTITUTE(ideadata.Categories,';',' | ')}"/>
<apex:outputText value=" -- {!ideadata.CreatedDate}"/>
<br /><br />
</span>
<apex:outputText escape="false" value="{!ideadata.Body}"/><br /><br />
<apex:outputLink styleClass="commentLink" style="color:#335CAD;" value="/apex/ViewPage?id={!ideadata.Id}">[{!ideadata.NumComments} {!$Label.Comments}]</apex:outputLink>
</apex:panelGroup>
<br />
</apex:panelGrid>
</apex:outputPanel>
</apex:dataList>