[SalesForce] Visualforce Page Not Showing on Global Action Vf Page List

I created a visualforce page:

enter image description here

But it does not show up on the list when I try and attach it to a global action:

enter image description here

I'm not sure why, seems simple enough and does appear in another dev environment I am using.

Here is the apex class which is related to the page – I don't think it needs to be looked at to understand the gist of the question though:

    public class createQuoteButton 
{
    //Properties
    String   thePageUrl          = '';
    Account  theAccount          = new Account(); 
    String   theAccountID        = null;
    Decimal  theCustID           = null;
    Contact  theDefaultContact   = new Contact();
    String   theDefaultContactId = null;
    String   theUsersInitials    = '';
    String   theTekUri           = '';

    private ApexPages.StandardController stdController;

    public  String  redirectUrl {public get; private set;}
    public  Boolean shouldRedirect {public get; private set;}
    public  String  errorMessage {public get; private set;}
    public  Boolean shouldError {public get; private set;}   
    public  ID      getDefaultContactId {public get; private set;} 

    // Constructor - this only really matters if the autoRun function doesn't work right     
    public createQuoteButton(ApexPages.StandardController stdController) {        
        this.theAccount    = (Account) stdController.getRecord();
        this.stdController = stdController;
        shouldRedirect     = false;
        shouldError        = true;
        errorMessage       = 'The autoRun method failed. Please contact IT.';
    } 

    // Code invoked on page load.      
    public PageReference autoRun()
    {           
        String thePageAccountId = ApexPages.currentPage().getParameters().get('id'); 
        String thePageUrl       = ApexPages.currentPage().getUrl();
        String theUsersId       = UserInfo.getUserId();
        User   theUser          = [SELECT Alias FROM User WHERE Id =:theUsersId LIMIT 1]; 
        String theUsersAlias    = theUser.Alias;

        shouldError = false;

        // Display the Visualforce page's error message if no Id is passed over 
        if (thePageAccountId == null){
            shouldError  = true;
            errorMessage = 'Could not get the Page Account Id.'; 
            return null;
        }

        Account theAccount = [select Id, External_Cust_ID__c from Account where id =:thePageAccountId Limit 1];
        theDefaultContactId = getDefaultContactId(); 
        theAccountID        = theAccount.Id;
        theCustId           = theAccount.External_Cust_ID__c;

        if (theDefaultContactId == null){
            shouldError  = true;
            errorMessage = 'Could not get the Contact Id. You need to have one contact for the account.'; 
            return null;        
        }

        if (theCustId == null){
            shouldError  = true;
            errorMessage = 'There is no cust id for this account. This is required for making an SRO. Please try again in a moment. If it continues to fail, contact IT.'; 
            return null;
        }       

        shouldRedirect = true;
        theTekUri      = 'tek://new?salesforce=1&sro_type=quote&cust_id=' + theCustId;
        theTekUri      = theTekUri + '&intakeby=' + theUsersAlias + '&person_id=' + theDefaultContactId;  
        redirectUrl    = stdController.view().getUrl();        

        return null;

        // Redirect the user to where ever you want to go.
        // PageReference pageRef = new PageReference('/');
        // return pageRef;    
    }

    private Id getDefaultContactId(){
        String thePageAccountId = ApexPages.currentPage().getParameters().get('id');

        try {
            theDefaultContact = [SELECT id FROM Contact WHERE AccountId =:thePageAccountId AND Default_Contact__c = TRUE LIMIT 1];
        } catch(Exception e) {
            theDefaultContact = null;
        }

        if(theDefaultContact == null){
            try {
                theDefaultContact = [SELECT id FROM Contact WHERE AccountId =:thePageAccountId LIMIT 1];
            } catch(Exception e) {
                theDefaultContact = null;
            }
        }

        if(theDefaultContact == null)
             return null;

        return theDefaultContact.Id;
    }

    public string getTheTekUri(){
        return theTekUri;
    }    
}

Best Answer

Visualforce pages using standard controller are not available for visualforce based global actions. If you replace markup

standardcontroller="Account" extensions="createQuoteButton"

with

controller="createQuoteButton"

your page would be available for global actions.

Related Topic