如何以编程方式在Salesforce中使DocuSign信封无效? [英] How do I programatically void a DocuSign envelope in Salesforce?

查看:52
本文介绍了如何以编程方式在Salesforce中使DocuSign信封无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DocuSign For Salesforce应用程序。作为我们工作流程的一部分,我们将在满足某些条件时创建信封,但是如果不再满足条件,我需要能够通过Apex触发器使信封无效。

I'm using the DocuSign For Salesforce app. As part of our workflow, we create envelopes when certain conditions are met, but I need to be able to void the envelope through an Apex trigger if the conditions are no longer met.

DocuSign应用程序的文档详细介绍了如何创建信封,但没有提及通过Apex清空信封。

The documentation for the DocuSign app goes into detail on how to create envelopes, but doesn't mention voiding an envelope through Apex.

我知道可以在Salesforce之外使用API​​,但我希望将整个过程保留在Salesforce中。

I know it's possible to use the API outside of Salesforce, but I'd like to keep the entire process in Salesforce if possible.

推荐答案

这是一个简单的客户端,您可以使用它来清空顶点的信封。

Here's a simple client that you can use to void envelopes from apex.

public with sharing class DocusignClient {
    private static final String USERNAME = Label.docusign_username;
    private static final String PASSWORD = Label.docusign_password;    
    private static final String INTEGRATOR_KEY = label.docusign_integratorKey;
    private static final String ACCOUNT_ID = label.docusign_accountId;
    // for production use 'www.docusign.net/restapi/v2'
    // for sandbox use 'https://demo.docusign.net/restapi/v2'
    private static final String BASE_URL = label.docusign_baseurl;
    private static final String AUTH_TEMPLATE = '<DocuSignCredentials><Username>{0}</Username><Password>{1}</Password><IntegratorKey>{2}</IntegratorKey></DocuSignCredentials>';
    private static final String STATUS_VOID = 'voided';


    public HttpResponse voidEnvelope(String envelopeId, String voidReason){
        String endpoint = String.format('{0}/accounts/{1}/envelopes/{2}', new String[]{BASE_URL, ACCOUNT_ID, envelopeId});

        DocusignStatusRequest statusUpdate = new DocusignStatusRequest();
        statusUpdate.status = STATUS_VOID;
        statusUpdate.voidedReason = voidReason;

        // initialize the api client for the desired environment
        Http h = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endpoint);
        request.setMethod('PUT');
        request.setHeader('X-DocuSign-Authentication', String.format(AUTH_TEMPLATE, new String[]{USER_NAME,PASS_WORD,INTEGRATOR_KEY}));
        request.setBody(JSON.serialize(statusUpdate));

        return h.send(request);
    }

    public class DocusignStatusRequest{
        public String status {get; set;}
        public String voidedReason {get; set;}
    }
}

这篇关于如何以编程方式在Salesforce中使DocuSign信封无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆