Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

createServiceRequest(ServiceRequestInput)

Create a service catalog request for a Unified Catalog product.

API Version

63.0

Requires Chatter

No

Signature

public static ConnectApi.ServiceRequestOutput createServiceRequest(ConnectApi.ServiceRequestInput ServiceRequestInput)

1ConnectApi.ServiceAutomationFamily, createServiceRequest, [ConnectApi.ServiceRequestInputRepresentation], ConnectApi.ServiceRequestOutputRepresentation

Parameters

ServiceRequestInput
Type: ConnectApi.ServiceRequestInputRepresentation
Input details for the service catalog request, including product, attributes, and optional context.

Return Value

Type: ConnectApi.ServiceRequestOutputRepresentation

Output containing details of the created service catalog request and anchor record information.

Usage

This method persists the submitted attributes, executes the product's configured intake and preprocessor logic, starts the associated fulfillment flow, creates the service catalog request, and returns the created request with its anchor record details.

Example

Here's an example of how to create the service catalog request from Apex code.

1### Create a Service Catalog Request
2
3The following example demonstrates how to create a Service Catalog Request using Apex. It shows how to provide custom attributes, context attributes, the originating record, and product attributes.
4
5```apex
6// Create the Service Catalog Request input
7ConnectApi.ServiceRequestInput input = new ConnectApi.ServiceRequestInput();
8
9// Specify the Service Catalog Product
10input.productId = '01tXXXXXXXXXXXXXXX';
11
12// Specify custom attribute values
13input.attributes = new Map<String, Object>{
14    'priority' => 'High'
15};
16
17// Specify the originating record.
18// Supported record types include Case, Incident, and ServiceRequest.
19input.createdFromRecord = '500XXXXXXXXXXXXXXX';
20
21// Optional: Specify Context Definition attribute values.
22// Context attributes can contain nested maps and lists.
23Map<String, Object> context = new Map<String, Object>{
24    'contextDefinition_Case' => new Map<String, Object>{
25        'contextDefinition_Detail' => new List<Object>{
26            new Map<String, Object>{
27                'detailName' => 'Example data',
28                'contextDefinition_SubDetail' => new List<Object>{
29                    new Map<String, Object>{
30                        'subDetailName' => 'Example sub-detail'
31                    }
32                }
33            }
34        },
35        'caseSubType' => 'Example'
36    },
37    'contextDefinition_Account' => new Map<String, Object>{
38        'accountName' => 'Example Account'
39    }
40};
41
42input.context = context;
43
44// Optional: Specify product attributes.
45// Available starting with API version 64.0.
46ConnectApi.ServiceAutomationProductAttributeInputRepresentation productAttribute =
47    new ConnectApi.ServiceAutomationProductAttributeInputRepresentation();
48
49productAttribute.id = '01tXXXXXXXXXXXXXXX';
50productAttribute.quantity = 2;
51
52input.productAttributes =
53    new List<ConnectApi.ServiceAutomationProductAttributeInputRepresentation>{
54        productAttribute
55    };
56
57// Create the Service Catalog Request
58ConnectApi.ServiceRequestOutput output =
59    ConnectApi.ServiceAutomationFamily.createServiceRequest(input);
60
61// Read the response
62System.debug(output.status);
63System.debug(output.serviceRequestId);
64System.debug(output.anchorObjectType);
65```
66
67**Notes:**
68
69* Replace the sample `productId` with the ID of the Service Catalog Product.
70* Replace `createdFromRecord` with the ID of the originating Case, Incident, or ServiceRequest.
71* The `attributes` map is used to provide custom attribute values.
72* The `context` map is used to provide Context Definition attribute values and supports nested maps and lists.
73* `productAttributes` is optional and is available starting with API version 64.0.
74* The returned `serviceRequestId` identifies the created Service Catalog Request.