+ Start a Discussion
Vincent van Drunen LittelVincent van Drunen Littel 


I have a script here that  I found and is almost perfect for what I need.. although when pressing the button "add competition" i need it to be added to a different object "Test Competitors" which is a related list shown in page of  "Account" (related list).
Could anybody "tweak"/ adjust this script accordingly!? 
Also I need this VF page to be popping up when clicking "new test competition" on the related list as picture below
User-added image

If need anymore info please let me know.. I really appreciate the help!!

Thanks Vincent
Best Answer chosen by Vincent van Drunen Littel
Krishna SambarajuKrishna Sambaraju
Please refer to the solution I have given for the question https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BLs7IAG 

All Answers

SonamSonam (Salesforce Developers) 
Could you please share the script and also explain what needs to be added to the test competitions object? Do you wish to create a new test competition? if yes, where will you get the values to create the new record in the object?
Vincent van Drunen LittelVincent van Drunen Littel
Hi Sonam, 

here is the script and controller.

When clicking the button "add competition" i would like it to create a new record in object "new test competition" which then is shown in the related list on Accounts.
The records shown on the page are already existing accounts but can be competition as well (if that makes sense)

thank you for your help!!

<apex:page  controller="AccountSelectClassController"  sidebar="false">
    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                    inputCheckBox[i].checked = obj.checked;
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Add to Competition" action="{!processSelected}" rerender="table2"/>
            <apex:pageblockSection title="All Accounts" collapsible="false" columns="2">
                <apex:pageBlockTable value="{!wrapAccountList}" var="accWrap" id="table" title="All Accounts">
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    <apex:column value="{!accWrap.acc.Name}" />
                    <apex:column value="{!accWrap.acc.BillingState}" />
                    <apex:column value="{!accWrap.acc.Phone}" />
                <apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" title="Selected Accounts">
                    <apex:column value="{!c.Name}" headerValue="Account Name"/>
                    <apex:column value="{!c.BillingState}" headerValue="Billing State"/>
                    <apex:column value="{!c.Phone}" headerValue="Phone"/>

public class AccountSelectClassController {
    //Our collection of the class/wrapper objects wrapAccount
    public List<wrapAccount> wrapAccountList {get; set;}
    public List<Account> selectedAccounts{get;set;}
    public AccountSelectClassController(){
        if(wrapAccountList == null) {
            wrapAccountList = new List<wrapAccount>();
            for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 50]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapAccountList.add(new wrapAccount(a));
    public void processSelected() {
    selectedAccounts = new List<Account>();
        for(wrapAccount wrapAccountObj : wrapAccountList) {
            if(wrapAccountObj.selected == true) {
Krishna SambarajuKrishna Sambaraju
Please refer to the solution I have given for the question https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BLs7IAG 
This was selected as the best answer
Vincent van Drunen LittelVincent van Drunen Littel
I would like to thank Krishna for all the work and effort he put in to help me with this big problem.
Amazing dedication to a problem that has nothing to do with him! 

You dont know how thankful I am for the help... this man deserves a reward!