Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yongbozuo committed Sep 27, 2023
1 parent 7bd6c85 commit 70950a1
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 198 deletions.
4 changes: 4 additions & 0 deletions ServiceDocumentSamples/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
.sfdx
.vscode

# Ignore apex cls and apex trigger files:
**/classes/FireCreateServiceDocumentInvocableAction.cls
**/triggers/ServiceDocumentCreation.trigger

coverage/
Original file line number Diff line number Diff line change
@@ -1,64 +1,76 @@
public with sharing class FireCreateServiceDocumentInvocableAction {
private static final String API_VERSION = 'v58.0';

private static final String API_VERSION = 'v58.0';
private static final String CREATE_SERVICE_DOCUMENT_ACTION_PATH =
'/services/data/' +
API_VERSION +
'/actions/standard/createServiceDocument';

private static final String CREATE_SERVICE_DOCUMENT_ACTION_PATH = '/services/data/'+ API_VERSION +'/actions/standard/createServiceDocument';
private static final String AUTHORIZATION_HEADER = 'Authorization';
private static final String AUTHORIZATION_BEARER_PREFIX = 'Bearer ';

private static final String AUTHORIZATION_HEADER = 'Authorization';
private static final String AUTHORIZATION_BEARER_PREFIX = 'Bearer ';
private static final String CONTENT_TYPE_HEADER = 'Content-Type';
private static final String CONTENT_TYPE_JSON = 'application/json';

private static final String CONTENT_TYPE_HEADER = 'Content-Type';
private static final String CONTENT_TYPE_JSON = 'application/json';
private static final String ACCEPT_HEADER = 'Accept';

private static final String ACCEPT_HEADER = 'Accept';
/**
* recordId: recordId to generate service document for. WO/WOLI/SA id
* templateId: The ID of Service document template to generate document for. The ID starts with '0M0'
* locale: (Optional) Locale to generate the document in. Example valid formats: 'ru', 'ru_PL'
* title: (Optional) Used to name the document saved
*/
@future(callout=true)
public static void TriggerCreateServiceDocumentInvocableAction(
String recordId,
String templateId,
String locale,
String title
) {
// System.debug('Attempting to queue Create Service Document');
// System.debug('RecordId: ' + recordId);
// System.debug('TemplateId: ' + templateId);
// System.debug('Locale: ' + locale);
// System.debug('Title: ' + title);

/**
* recordId: recordId to generate service document for. WO/WOLI/SA id
* templateId: The ID of Service document template to generate document for. The ID starts with '0M0'
* locale: (Optional) Locale to generate the document in. Example valid formats: 'ru', 'ru_PL'
* title: (Optional) Used to name the document saved
*/
@future (callout=true)
public static void TriggerCreateServiceDocumentInvocableAction(String recordId, String templateId, String locale, String title) {
String sessionId = UserInfo.getSessionId();

// System.debug('Attempting to queue Create Service Document');
// System.debug('RecordId: ' + recordId);
// System.debug('TemplateId: ' + templateId);
// System.debug('Locale: ' + locale);
// System.debug('Title: ' + title);
HttpRequest httpRequest = new HttpRequest();

String sessionId = UserInfo.getSessionId();
httpRequest.setMethod('POST');
httpRequest.setEndpoint(
URL.getOrgDomainUrl().toExternalForm() +
CREATE_SERVICE_DOCUMENT_ACTION_PATH
);
httpRequest.setHeader(
AUTHORIZATION_HEADER,
AUTHORIZATION_BEARER_PREFIX + sessionId
);
httpRequest.setHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON);
httpRequest.setHeader(ACCEPT_HEADER, CONTENT_TYPE_JSON);

HttpRequest httpRequest = new HttpRequest();
JSONGenerator jg = JSON.createGenerator(false);
jg.writeStartObject();
jg.writeFieldName('inputs');
jg.writeStartArray();

httpRequest.setMethod('POST');
httpRequest.setEndpoint(URL.getOrgDomainUrl().toExternalForm() + CREATE_SERVICE_DOCUMENT_ACTION_PATH);
httpRequest.setHeader(AUTHORIZATION_HEADER, AUTHORIZATION_BEARER_PREFIX + sessionId);
httpRequest.setHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON);
httpRequest.setHeader(ACCEPT_HEADER, CONTENT_TYPE_JSON);

JSONGenerator jg = JSON.createGenerator(false);
jg.writeStartObject();
jg.writeFieldName('inputs');
jg.writeStartArray();

jg.writeStartObject();
jg.writeObjectField('recordId', recordId);
jg.writeObjectField('templateId', templateId);
if (locale != null) {
jg.writeObjectField('locale', locale);
}
if (title != null) {
jg.writeObjectField('title', title);
}
jg.writeEndObject();
jg.writeEndArray();
jg.writeEndObject();
jg.writeStartObject();
jg.writeObjectField('recordId', recordId);
jg.writeObjectField('templateId', templateId);
if (locale != null) {
jg.writeObjectField('locale', locale);
}
if (title != null) {
jg.writeObjectField('title', title);
}
jg.writeEndObject();
jg.writeEndArray();
jg.writeEndObject();

httpRequest.setBody( jg.getAsString() );
httpRequest.setBody(jg.getAsString());

Http http = new Http();
HttpResponse response = http.send(httpRequest);
System.debug(response.getBody());
}
}
Http http = new Http();
HttpResponse response = http.send(httpRequest);
System.debug(response.getBody());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<status>Active</status>
</ApexClass>
</ApexClass>
Loading

0 comments on commit 70950a1

Please sign in to comment.