You need to sign in to do that
Don't have an account?
Shannon Andreas 1
Trigger help - not firing when I need it to!
We have a process where the rep creates a physical contract (not a Salesforce contract record) using DrawLoop. There is a button on the opportunity or quote the rep can push to initiate the process. When the document is created, there is an option to send using DocuSign. When the rep clicks the link, it sends to DocuSign, thereby creating a DocuSign Status record (DocuSign_Status custom object).
I wrote a trigger that would create a contract when the DocuSign Status field "Envelope Status = Completed". It works...but only when I create the DocuSign Status record manually and change the trigger from after insert to after update. If it is created through the DocuSign workflow that is set up, it does not create the contract. Also, changing to after update messes up my test class as well, no coverage.
What am I missing?
Here is the original trigger that passes testing:
trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after insert)
{
List<Contract> ctr = new List<Contract>();
for(dsfs__DocuSign_Status__c dsfs : Trigger.new)
{
if(dsfs.dsfs__Envelope_Status__c == 'Completed')
{
Contract c = new Contract(Name = dsfs.Name,
Status = 'Draft',
Total_Contract_Value__c =dsfs.Total_Contract_Value__c,
StartDate = dsfs.Contract_Start_Date__c,
Payment_Status__c = 'Ready to be Invoiced',
AccountId = dsfs.dsfs__Company__c,
Opportunity_Name__c = dsfs.dsfs__Opportunity__c);
ctr.add(c);
}
}
if(ctr.size() > 0)
{
System.debug('-ctr------->'+ctr.size());
insert ctr;
}
}
Thanks for your help!
Shannon
I wrote a trigger that would create a contract when the DocuSign Status field "Envelope Status = Completed". It works...but only when I create the DocuSign Status record manually and change the trigger from after insert to after update. If it is created through the DocuSign workflow that is set up, it does not create the contract. Also, changing to after update messes up my test class as well, no coverage.
What am I missing?
Here is the original trigger that passes testing:
trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after insert)
{
List<Contract> ctr = new List<Contract>();
for(dsfs__DocuSign_Status__c dsfs : Trigger.new)
{
if(dsfs.dsfs__Envelope_Status__c == 'Completed')
{
Contract c = new Contract(Name = dsfs.Name,
Status = 'Draft',
Total_Contract_Value__c =dsfs.Total_Contract_Value__c,
StartDate = dsfs.Contract_Start_Date__c,
Payment_Status__c = 'Ready to be Invoiced',
AccountId = dsfs.dsfs__Company__c,
Opportunity_Name__c = dsfs.dsfs__Opportunity__c);
ctr.add(c);
}
}
if(ctr.size() > 0)
{
System.debug('-ctr------->'+ctr.size());
insert ctr;
}
}
Thanks for your help!
Shannon
Please change your test class with below code :
@isTest
private class TestCreateContractDocSignCompTrigger
{
static testMethod void validateCreateContractDocuSignComp()
{
Account a = new Account(
Name = 'Test Account');
insert a;
Opportunity o = new Opportunity(
Name = 'Test Opp',
Ready_for_Contract__c = true,
CloseDate = System.Today(),
AccountId = a.Id,
StageName = 'Signed / Closed Sale',
Amount = decimal.valueof('6995'));
Test.StartTest();
insert o;
dsfs__DocuSign_Status__c dsfs = new dsfs__DocuSign_Status__c();
dsfs.dsfs__Company__c = o.AccountId;
dsfs.dsfs__Opportunity__c = o.Id;
dsfs.dsfs__Envelope_Status__c = 'Draft';
dsfs.dsfs__DocuSign_Envelope_ID__c = '1001A123-1234-5678-1D84-F8D44652A382';
dsfs.dsfs__Subject__c = 'Document for eSignature';
insert dsfs;
dsfs.dsfs__Envelope_Status__c = 'Completed';
update dsfs;
List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
//System.assertNotEquals(1stContr,null);
Test.StopTest();
}
}
Please let me know if I can help you more.
Thanks,
Vishal
All Answers
In dsfs__DocuSign_Status__c object, field dsfs__Envelope_Status__c always mark completed in a update call beacuse as a process docusign first send an envelope to the signer and once signer reviewed contarct and signed it, dsfs__DocuSign_Status__c change the envelop status equal to complete, so I suggest to keep your code in After update.
Please let me know if I am missing something.
Thanks,
Vishal
Please, I need help with my test class now. I am getting "0" coverage even though it is passing Run Test. Does it have something to do with how we are inserting the dsfs record? Maybe I have to start the test after we insert dsfs? Please advise and thank you very much!
@isTest
private class TestCreateContractDocSignCompTrigger
{
static testMethod void validateCreateContractDocuSignComp()
{
Account a = new Account(
Name = 'Test Account');
insert a;
Opportunity o = new Opportunity(
Name = 'Test Opp',
Ready_for_Contract__c = true,
CloseDate = System.Today(),
AccountId = a.Id,
StageName = 'Signed / Closed Sale',
Amount = decimal.valueof('6995'));
Test.StartTest();
insert o;
dsfs__DocuSign_Status__c dsfs = new dsfs__DocuSign_Status__c();
dsfs.dsfs__Company__c = o.AccountId;
dsfs.dsfs__Opportunity__c = o.Id;
dsfs.dsfs__Envelope_Status__c = 'Completed';
dsfs.dsfs__DocuSign_Envelope_ID__c = '1001A123-1234-5678-1D84-F8D44652A382';
dsfs.dsfs__Subject__c = 'Document for eSignature';
insert dsfs;
List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
//System.assertNotEquals(1stContr,null);
Test.StopTest();
}
}
Please change your test class with below code :
@isTest
private class TestCreateContractDocSignCompTrigger
{
static testMethod void validateCreateContractDocuSignComp()
{
Account a = new Account(
Name = 'Test Account');
insert a;
Opportunity o = new Opportunity(
Name = 'Test Opp',
Ready_for_Contract__c = true,
CloseDate = System.Today(),
AccountId = a.Id,
StageName = 'Signed / Closed Sale',
Amount = decimal.valueof('6995'));
Test.StartTest();
insert o;
dsfs__DocuSign_Status__c dsfs = new dsfs__DocuSign_Status__c();
dsfs.dsfs__Company__c = o.AccountId;
dsfs.dsfs__Opportunity__c = o.Id;
dsfs.dsfs__Envelope_Status__c = 'Draft';
dsfs.dsfs__DocuSign_Envelope_ID__c = '1001A123-1234-5678-1D84-F8D44652A382';
dsfs.dsfs__Subject__c = 'Document for eSignature';
insert dsfs;
dsfs.dsfs__Envelope_Status__c = 'Completed';
update dsfs;
List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
//System.assertNotEquals(1stContr,null);
Test.StopTest();
}
}
Please let me know if I can help you more.
Thanks,
Vishal
Thanks,
Vishal