0

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;
    }    
}

2 Answers 2

1

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.

5
  • Ah okay, what if I want to leave in the standardController="Account" - would I have to crate a different kind of action? Are those the actions inside the objects?
    – dmgig
    Jun 21, 2016 at 17:11
  • I feel that would not be possible. Specifying standard controller will indirectly mean that this page is linked to some record id which can not be true for global action as they usually mean start of some process. Jun 21, 2016 at 17:17
  • Hm, see I actually am using an Account ID, trying to run this from the accounts page only, I guess I'm wondering - maybe I don't need a global action but something else?
    – dmgig
    Jun 21, 2016 at 17:23
  • You can create a custom button. Customize-> Accounts-> Button Links and Actions. Create a new button to open your page and place it on required page layouts. Jun 21, 2016 at 17:30
  • Yes - that was it. Thank you very, very much. Do you want to add that last part to the answer? If you think it is necessary, I am accepting this.
    – dmgig
    Jun 21, 2016 at 17:41
0

I was able to hook up a VF page with Standard Controller to a Global Action. You first need to temporarily update your VF page code to reference a custom controller (instead of a standard controller): for example: controller="createQuoteButton". Then the VF page will be available for selection within your Global Action. Select the VF page within the Global Action, save the Global Action, then update your code on the VF page to the original code. Kind of a weird workaround hack but it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .