+ Start a Discussion
satakshisatakshi 

Can not see visualforce page in the content source drop down

Hello,

I am not able to create custom button as in a cotent source drop down list there is no visualforce page to select.

My code is 
Controller:

public with sharing class MyCompController
{    
    Map<Integer, Account> AccountIdList = new Map<Integer, Account>();

    public MyCompController() {
        Integer i = 0;
        for (Account a : [SELECT Id, Name FROM Account]) {
            AccountIdList.put(i, a);
            i++;
        }
    }

    public Map<Integer, Account> getAccountIdList() {
        return AccountIdList;
    }
}

VF Page:

<apex:page controller="MyCompController"> <apex:form > <apex:repeat value="{!AccountIdList}" var="accNum"> <apex:outputText value="({!AccountIdList[accNum]}, {!AccountIdList[accNum].Name})" /><br/> </apex:repeat> </apex:form> </apex:page>
Best Answer chosen by satakshi
Ankur Saini 9Ankur Saini 9
Hi Satakshi,
use standardController="Planned_visit__c"  instead of standardController="account"  with my Ist code.

Thanks 
Ankur Saini
http://mirketa.com

All Answers

Ankur Saini 9Ankur Saini 9
Hi satakshi, 
If you want to create a custom button on Account object or any other custom object, you must specify the standard controller as mention below

try this:--

public with sharing class MyCompController

    public MyCompController(ApexPages.StandardController controller) {
       Integer i = 0;
         for (Account a : [SELECT Id, Name FROM Account]) {
             AccountIdList.put(i, a);
              i++;
        }
    }
  
    Map<Integer, Account> AccountIdList = new Map<Integer, Account>();
    
    public Map<Integer, Account> getAccountIdList() {
        return AccountIdList;
    }
}



<apex:page standardController="account" extensions="MyCompController"> <apex:form > <apex:repeat value="{!AccountIdList}" var="accNum"> <apex:outputText value="({!AccountIdList[accNum]}, {!AccountIdList[accNum].Name})" /><br/> </apex:repeat> </apex:form> </apex:page>
satakshisatakshi
hello   Ankur Saini 9


I am getting this error after trying your code
 Loop variable must be an SObject or list of Account

Thanks,
Satakshi
swati_sehrawatswati_sehrawat
Hello Satakshi,

Can you please tell on which object you are trying to create the custom button.

With below code am able to save page and class both without any error.

Class:

public with sharing class MyCompController{ 
    public MyCompController(ApexPages.StandardController controller) {
       Integer i = 0;
         for (Account a : [SELECT Id, Name FROM Account]) {
             AccountIdList.put(i, a);
              i++;
        }
    }
    Map<Integer, Account> AccountIdList = new Map<Integer, Account>();
    
public Map<Integer, Account> getAccountIdList() {
        return AccountIdList;
    }
}

Page: 

<apex:page standardController="account" extensions="MyCompController"> 
<apex:form > 
<apex:repeat value="{!AccountIdList}" var="accNum"> 
<apex:outputText value="({!AccountIdList[accNum]}, {!AccountIdList[accNum].Name})" /><br/> 
</apex:repeat> 
</apex:form> 
</apex:page>
swati_sehrawatswati_sehrawat
User-added image
Ankur Saini 9Ankur Saini 9
Hi Satakshi,

I repeat, If you want to create a custom button on Account object 

My Ist Code is running without any error for Detail Page Button of Account

My 2nd Code is also running without any error for List View Button of Account

2nd Code:--

public with sharing class MyCompController

    public MyCompController(ApexPages.StandardSetController controller) {
        Integer i = 0;
         for (Account a : [SELECT Id, Name FROM Account]) {
             AccountIdList.put(i, a);
              i++;
        }
    }
  
    Map<Integer, Account> AccountIdList = new Map<Integer, Account>();
    
    public Map<Integer, Account> getAccountIdList() {
        return AccountIdList;
    }
}


<apex:page standardController="account" extensions="MyCompController" recordSetVar="acc"> 
  <apex:form > 
    <apex:repeat value="{!AccountIdList}" var="accNum">
      <apex:outputText value="({!AccountIdList[accNum]}, {!AccountIdList[accNum].Name})" /><br/>
    </apex:repeat>
  </apex:form> 
</apex:page>


Thanks 
Ankur Saini
 
satakshisatakshi
I want custom button on custom object "planned visit". I want list of record from account object on this custom button placed on custom object("Planned visit")
Ankur Saini 9Ankur Saini 9
Hi Satakshi,
use standardController="Planned_visit__c"  instead of standardController="account"  with my Ist code.

Thanks 
Ankur Saini
http://mirketa.com
This was selected as the best answer
satakshisatakshi
Hello All,

Thanks For the help

Regards,
Satakshi