+ Start a Discussion
Tom Blamire 24Tom Blamire 24 

visualforce record select from junction object

Hi,

Noob to VF and sutck.

I have a custom object called Hashtags(Hashtags__c) and then a junction object called Account Hashtags which has 2 fields - the account name and hashtag name. What i am trying to achieve is that when a user clicks new on the Account hashtags i want something to a list view whereby they can select multiple records (base on record type = Active) and they have it save back to the account.

I tried creating custom controllers but failed straight away - can someone please help?
srlawr uksrlawr uk
Sounds like what you probably want to do is create a custom visualforce page (with a custom controller) and then you can make that the "page override" for the "new" button on the Hashtag object.

This visualforce page/controller will want to extend the Hashtag object and will probably initially look something like this:
 
<apex:page standardController="Hashtag__c" extensions="ListSelectorExtention" >

// Here you will want to code up your page block table/standardsetcontroller output for the possible hashtags (and save button)


 <apex:pageBlockTable value="{!hashtagSetControllerRecords}" var="thisHash" id="hashTable">

</apex:pageBlockTable>


</apex:page>

your controller extenstion will probs be a bit like this (with a lot more work, obviously - this is hand typed/non compiling!)
 
public with sharing class ListSelectorExtension {
    
    public hashtag { get; set; }

    public ApexPages.StandardSetController hashtagSetController { get; set; }

    public ListSelectorExtension (ApexPages.StandardController controller) {
        this.hashtag = (hashtag__c)controller.getRecord();

        // Set up the list of possible hashtags with SOQL 
        hashtagSetController = new ApexPages.StandardSetController(/* query */);

}

public list<Hashtag__c> getHashtagSetControllerRecords {
    return hashtagSetController.getRecords();
}

public pageReference save() {
//    save your stuff here and return the user
}

Hopefully that's a good starter for you? I don't have the 12 spare hours before Christmas to code the whole solution for ya ;)
Tom Blamire 24Tom Blamire 24
thanks srlawr - i have no idea how to pronounce that so will call you Bob for ease.

Bob, tried creating these but getting compile errors on line 3 of the extension - any ideas? 
srlawr uksrlawr uk
hi! It's often pronounced "slaw" but its more of an internet pseudonym for typing only, and I get very nervous when people use it out loud in real life because it means the two have clashed once again.

Ah yes, line 3 has a couple of problems for a compiler.. namely it doesn't have a type
 
public Hashtag__c hashtag { get; set; }

I suspect there are a lot more compiler problems in that pseudo-code that are going to get in your way (and indeed the completion of the code which I have scattered around in comments (such as using the StandardSetController) is fairly complex stuff. There is lots of help out there (including this forum). So I do wish you luck! Hopefully the approach I am advocating is the best one in this situation ;)