+ Start a Discussion
BarryPlumBarryPlum 

New Idea Visualforce page

I'm 99% to a page with a decent layout for internal users.  This is probably trivial, but for whatever reason, I can't find it.  We only have one community, and it seems really stupid to force people to choose the community when they are creating an idea.

 

How do I 'hard code' the communityid in the VF page.

 

Here is my code that works, if I search and then select, my one community:

 

<apex:page standardController="idea">

<apex:form >

<apex:pageBlock title="New Idea">

<apex:pageBlockButtons >

<apex:commandButton action="{!save}" value="Save"/>

</apex:pageBlockButtons>

<apex:pageBlockSection title="Idea Details" columns="1">

<apex:inputField style="width:250px" value="{!idea.title}"/>

<apex:inputField required="true" value="{!idea.CommunityId}"/>

<apex:inputField required="true" value="{!idea.category}"/>

<apex:inputField required="true" value="{!idea.Requested_Priority__c}"/> <apex:inputField required="true" style="width:600px" value="{!idea.Business_Case__c}"/>

<apex:inputField required="true" style="width:600px" value="{!idea.body}"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

 

 I've tried various tags, but there should be some way to just say that {!idea.communityid} = <id>

 

Also, I hope the answer isn't that I have to write a controller extension JUST to hard code this value... 

Message Edited by BarryPlum on 12-22-2009 09:37 AM
Best Answer chosen by Admin (Salesforce Developers) 
BarryPlumBarryPlum

Figured it out... at least using a controller...

 

Changed my controller to:

 

 

public with sharing class ideaExtension {

Private final Idea idea;

public ideaExtension(ApexPages.StandardController stdController) {

this.idea = (Idea)stdController.getRecord();

}

public String getCommunityId() {

return idea.CommunityId ='09a6000000003Nf';

}

}

 

 

 

Message Edited by BarryPlum on 12-30-2009 08:44 AM

All Answers

Ron HessRon Hess
i think you can use < apex : variable   to assign a string to an expression
BarryPlumBarryPlum

Thanks Ron.  That's exactly what I was hoping to do... unfortunately, that didn't work.

 

Tried first:

<apex:variable var="{!idea.CommunityId}" value="09a6000000003Nf"/>

 

 But it said that var had to be a literal... so I thought maybe I have to turn it around...

 

<apex:variable var="09a6000000003Nf" value="{!idea.CommunityId}"/>

 

Is what I have now, but that still doesn't work. No obvious error on the page, but the message in the system log is that communityID is a required field that's missing.

 

Am I doing it wrong, or is there just no way to do this without a controller extension? 

 

 

BarryPlumBarryPlum

I decided to go ahead and try creating a VERY simple extension to set the CommunityId variable... but I still can't figure out how to assign that to the idea.communityId variable in the form.

 

Here's my controller:

 

public with sharing class ideaExtension {

Private final Idea idea;

public ideaExtension(ApexPages.StandardController stdController) {

this.idea = (Idea)stdController.getRecord();

}

public String getCommunityId() {

return '09a6000000003Nf';

}

}

 

 I tried a couple ways to set it, here's the last one:  

<apex:variable var="CommunityId" value="{!CommunityId}" />

 Any help would be appreciated...

 

 

Message Edited by BarryPlum on 12-30-2009 07:51 AM
BarryPlumBarryPlum

Figured it out... at least using a controller...

 

Changed my controller to:

 

 

public with sharing class ideaExtension {

Private final Idea idea;

public ideaExtension(ApexPages.StandardController stdController) {

this.idea = (Idea)stdController.getRecord();

}

public String getCommunityId() {

return idea.CommunityId ='09a6000000003Nf';

}

}

 

 

 

Message Edited by BarryPlum on 12-30-2009 08:44 AM
This was selected as the best answer
yvk431yvk431

Barry,

 

Can you clarify, why you want to add a static value to a input field.

 

Anyways , didn't you ever tried java script

 

<script>
    document.getElementById('page1:form1:pb1:pbs1:fieldname').value = 'test';
</script>

 

 

or try the following link

 

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=863

 

BarryPlumBarryPlum
In this case, we only use one community, for ideas.  It also happens to be a required field.  I hate using Javascript for something that should be able to be done on the server side.
adam_purkissadam_purkiss

I was able to get this done with something like this in the controller constructor (save button upserts object later):

 

 

String apideas = 'AP Ideas';
String internalcomm = 'Internal Community';

Community c;
			
if([SELECT count() FROM Community WHERE Name = :apideas limit 1] == 1)
    c = [SELECT Id FROM Community WHERE Name = :apideas limit 1];
else if([SELECT count() FROM Community WHERE Name = :internalcomm limit 1] == 1) // Salesforce default community name
    c = [SELECT Id FROM Community WHERE Name = :internalcomm limit 1];
			
if(c != null)
    newIdea = new Idea(CommunityId = c.Id);

 

 

This code allows me to create a managed package and later add community names to search for when installing into different orgs.  But I'm stuck on the apex:vote component!  Have you been able to permit voting in your custom page(s) without receiving the following error when one clicks on Promote or Demote?:

 

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

 

My page has this simple code with idea being a valid Idea id:

 

 

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

 

 

I've been stuck so I thought I'd try someone with experience in this particular "exposed wire" zone in Force.com. 

 

Thanks for any suggestions!!

Adam Purkiss

PSteves91PSteves91

Adam,

 

You might try this instead, since you're using 'idea'...:

<apex:vote id="thevote" objectId="{!idea.id}"/>
adam_purkissadam_purkiss

Thanks PSteve91.  It's actually the same thing. I just was unclear that the IdeaId is an Idea.Id passed into my Component.  But I did find a solution elsewhere on the boards and it was to include a rerender="someBlock" to the apex:vote component.  The working code now looks like the following:

 

 

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

<!-- ideaid is Idea.Id passed into my VF component -->

 

 

Cheers,

Adam

 

Richa_LearningRicha_Learning
Hi,

Can you please share the code for VF page and Class that you used for this. I am new to this development and am npt sure how to make this?

Thanks.
Richa
Chris over 9000Chris over 9000
​<apex:page standardController="idea" extensions="ideaExtension" showHeader="false">
<apex:form >
<apex:pageBlock title="New Idea">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Idea Details" columns="1">
<apex:variable var="CommunityId" value="{!CommunityId}" />
<apex:inputField style="width:250px" value="{!idea.title}"/>
<apex:inputField required="true" style="width:600px" value="{!idea.body}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
and the controller
public with sharing class ideaExtension {
Private final Idea idea;
public ideaExtension(ApexPages.StandardController stdController) {
this.idea = (Idea)stdController.getRecord();
}
public String getCommunityId() {
return idea.CommunityId ='09a30000000KU3W';
}
}