QuickAction Class

Use Apex to request and process actions on objects that allow custom fields, on objects that appear in a Chatter feed, or on objects that are available globally.

Namespace

System

Example

In this sample, the trigger determines if the new contacts to be inserted are created by a quick action. If so, it sets the WhereFrom__c custom field to a value that depends on whether the quick action is global or local to the contact. Otherwise, if the inserted contacts don’t originate from a quick action, the WhereFrom__c field is set to 'NoAction'.
trigger accTrig2 on Contact (before insert) {
    for (Contact c : Trigger.new) {
        if (c.getQuickActionName() == QuickAction.CreateContact) {
            c.WhereFrom__c = 'GlobaActionl';
        } else if (c.getQuickActionName() == Schema.Account.QuickAction.CreateContact) {
            c.WhereFrom__c = 'AccountAction';
        } else if (c.getQuickActionName() == null) {
            c.WhereFrom__c = 'NoAction';
        } else {
            System.assert(false);
        }
    }
}
This sample performs a global action—QuickAction.CreateContact–on the passed-in contact object.
public Id globalCreate(Contact c) { 
    QuickAction.QuickActionRequest req = new QuickAction.QuickActionRequest();
    req.quickActionName = QuickAction.CreateContact;
    req.record = c;
    QuickAction.QuickActionResult res = QuickAction.performQuickAction(req);
    return c.id;
}

QuickAction Methods

The following are methods for QuickAction. All methods are static.

describeAvailableQuickActions(parentType)

Returns metadata information for the available quick actions of the provided parent object.

Signature

public static List<QuickAction.DescribeAvailableQuickActionResult> describeAvailableQuickActions(String parentType)

Parameters

parentType
Type: String
The parent object type. This can be an object type name ('Account') or 'Global' (meaning that this method is called at a global level and not an entity level).

Return Value

Type: List<QuickAction.DescribeAvailableQuickActionResult>

The metadata information for the available quick actions of the parent object.

Example

// Called for Account entity.
List<QuickAction.DescribeAvailableQuickActionResult> result1 = 
    QuickAction.DescribeAvailableQuickActions('Account');  

// Called at global level, not entity level.
List<QuickAction.DescribeAvailableQuickActionResult> result2 = 
    QuickAction.DescribeAvailableQuickActions('Global');  

describeAvailableQuickActions(sObjectNames)

Returns the metadata information for the provided quick actions.

Signature

public static List<QuickAction.DescribeQuickActionResult> describeAvailableQuickActions(List<String> sObjectNames)

Parameters

sObjectNames
Type: List<String>
The names of the quick actions. The quick action name can contain the entity name if it is at the entity level ('Account.QuickCreateContact'), or 'Global' if used for the action at the global level ('Global.CreateNewContact').

Return Value

Type: List<QuickAction.DescribeQuickActionResult>

The metadata information for the provided quick actions.

Example

// First 3 parameter values are for actions at the entity level. 
// Last parameter is for an action at the global level.
List<QuickAction.DescribeQuickActionResult> result = 
    QuickAction.DescribeQuickActions(new List<String> {
        'Account.QuickCreateContact', 'Opportunity.Update1', 
        'Contact.Create1', 'Global.CreateNewContact' });

performQuickAction(quickActionRequest)

Performs the quick action specified in the quick action request and returns the action result.

Signature

public static QuickAction.QuickActionResult performQuickAction(QuickAction.QuickActionRequest quickActionRequest)

Parameters

quickActionRequest
Type: QuickAction.QuickActionRequest

Return Value

Type: QuickAction.QuickActionResult

performQuickAction(quickActionRequest, allOrNothing)

Performs the quick action specified in the quick action request with the option for partial success, and returns the result.

Signature

public static QuickAction.QuickActionResult performQuickAction(QuickAction.QuickActionRequest quickActionRequest, Boolean allOrNothing)

Parameters

quickActionRequest
Type: QuickAction.QuickActionRequest
allOrNothing
Type: Boolean
Specifies whether this operation allows partial success. If you specify false for this argument and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why.

Return Value

Type: QuickAction.QuickActionResult

performQuickActions(quickActionRequests)

Performs the quick actions specified in the quick action request list and returns action results.

Signature

public static List<QuickAction.QuickActionResult> performQuickActions(List<QuickAction.QuickActionRequest> quickActionRequests)

Parameters

quickActionRequests
Type: List<QuickAction.QuickActionRequest>

Return Value

Type: List<QuickAction.QuickActionResult>

performQuickActions(quickActionRequests, allOrNothing)

Performs the quick actions specified in the quick action request list with the option for partial success, and returns action results.

Signature

public static List<QuickAction.QuickActionResult> performQuickActions(List<QuickAction.QuickActionRequest> quickActionRequests, Boolean allOrNothing)

Parameters

quickActionRequests
Type: List<QuickAction.QuickActionRequest>
allOrNothing
Type: Boolean
Specifies whether this operation allows partial success. If you specify false for this argument and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why.

Return Value

Type: List<QuickAction.QuickActionResult>