You need to sign in to do that
Don't have an account?
Shannon Andreas 1
Attachment not attaching through Trigger
Hello friends!
First part of trigger works, second part where it is supposed to attach the doc does not. Can you please help?
trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
map<id,id> testmap = new map<id,id>();
list <attachment> attach = new list<attachment>();
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,
ContractTerm = Integer.valueOf(dsfs.Contract_Term_months2__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,dsfsid2__c = dsfs.id);
ctr.add(c);
}
}
if(ctr.size() > 0)
{
System.debug('-ctr------->'+ctr.size());
insert ctr;
}
for(contract con : ctr){
//map to put the value of docusign object as key and the contract object value as values
testmap.put(con.dsfsid2__c, con.id);
}
for(attachment att : [select id,parentid,body,name from attachment where parentid in : testmap.keyset()]){
if(testmap.containskey(att.parentid)){
attachment a = new attachment(name=att.name,body=att.body,parentid=testmap.get(att.parentid));
attach.add(a);
}
}
insert attach;
}
First part of trigger works, second part where it is supposed to attach the doc does not. Can you please help?
trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
map<id,id> testmap = new map<id,id>();
list <attachment> attach = new list<attachment>();
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,
ContractTerm = Integer.valueOf(dsfs.Contract_Term_months2__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,dsfsid2__c = dsfs.id);
ctr.add(c);
}
}
if(ctr.size() > 0)
{
System.debug('-ctr------->'+ctr.size());
insert ctr;
}
for(contract con : ctr){
//map to put the value of docusign object as key and the contract object value as values
testmap.put(con.dsfsid2__c, con.id);
}
for(attachment att : [select id,parentid,body,name from attachment where parentid in : testmap.keyset()]){
if(testmap.containskey(att.parentid)){
attachment a = new attachment(name=att.name,body=att.body,parentid=testmap.get(att.parentid));
attach.add(a);
}
}
insert attach;
}
It looks like you want some debug in there to check that the data you are expecting to be present is indeed present.
25.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
11:34:20.146 (146519867)|ENTERING_MANAGED_PKG|dsfs
11:34:20.155 (155733284)|SOQL_EXECUTE_BEGIN|[14]|Aggregations:0|SELECT Id, OrganizationType FROM Organization LIMIT 1
11:34:20.160 (160305378)|SOQL_EXECUTE_END|[14]|Rows:1
11:34:20.271 (271542059)|SOQL_EXECUTE_BEGIN|[32]|Aggregations:0|SELECT id, dsfs__ChatterUpdatesEnabled__c, dsfs__DocuSign_Envelope_ID__c, dsfs__Source_Object__c, dsfs__ChatterEnvSent__c, dsfs__ChatterEnvCompleted__c, dsfs__ChatterEnvDeclined__c, dsfs__ChatterEnvDelivered__c, dsfs__ChatterEnvVoided__c, dsfs__ChatterEnvSentText__c, dsfs__ChatterEnvCompletedText__c, dsfs__ChatterEnvDeclinedText__c, dsfs__ChatterEnvDeliveredText__c, dsfs__ChatterEnvVoidedText__c FROM DocuSign_Envelope__c WHERE DocuSign_Envelope_ID__c IN :tmpVar1
11:34:20.277 (277314520)|SOQL_EXECUTE_END|[32]|Rows:0
11:34:20.279 (279883474)|SOQL_EXECUTE_BEGIN|[242]|Aggregations:0|SELECT dsfs__DocuSign_EnvelopeID__c, dsfs__DocuSign_Signer_Type__c, dsfs__DSER_ContactID__c, dsfs__DocuSign_Signature_Name__c, dsfs__DSER_LeadID__c, dsfs__DSER_UserID__c, dsfs__DSER_CustomId__c, dsfs__DSER_CustomFeatures__c, dsfs__DSER_CustomFeaturesEx__c, dsfs__DSER_CustomName__c, d.Id, dsfs__Routing_Order__c, dsfs__Salesforce_Recipient_Type__c, dsfs__DocuSign_Recipient_Role__c, dsfs__RoleName__c FROM DocuSign_Envelope_Recipient__c d WHERE DocuSign_EnvelopeID__c IN :tmpVar1 ORDER BY d.Routing_Order__c ASC NULLS FIRST
11:34:20.286 (286220549)|SOQL_EXECUTE_END|[242]|Rows:0
11:34:20.287 (287753713)|SOQL_EXECUTE_BEGIN|[189]|Aggregations:0|SELECT dsfs__Attachment_NameEx__c, dsfs__Document_Name__c, dsfs__DocuSign_EnvelopeID__c FROM DocuSign_Envelope_Document__c WHERE DocuSign_EnvelopeID__c IN :tmpVar1
11:34:20.290 (290431890)|SOQL_EXECUTE_END|[189]|Rows:0
11:34:20.297 (297599356)|EXECUTION_STARTED
11:34:20.297 (297606788)|CODE_UNIT_STARTED|[EXTERNAL]|01qS0000000DJdo|CreateContractDocSignComp on DocuSign_Status trigger event AfterUpdate for [a0OS0000004Jl7V]
11:34:20.297 (297919598)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
11:34:20.297 (297949253)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
11:34:20.297 (297994889)|SYSTEM_CONSTRUCTOR_ENTRY|[6]|<init>()
11:34:20.298 (298011878)|SYSTEM_CONSTRUCTOR_EXIT|[6]|<init>()
11:34:20.298 (298040754)|SYSTEM_METHOD_ENTRY|[8]|List<dsfs__DocuSign_Status__c>.iterator()
11:34:20.298 (298061257)|SYSTEM_METHOD_EXIT|[8]|List<dsfs__DocuSign_Status__c>.iterator()
11:34:20.298 (298074310)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()
11:34:20.298 (298089398)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()
11:34:20.307 (307135917)|SYSTEM_METHOD_ENTRY|[15]|Integer.valueOf(Object)
11:34:20.307 (307182284)|SYSTEM_METHOD_EXIT|[15]|Integer.valueOf(Object)
11:34:20.307 (307710312)|SYSTEM_METHOD_ENTRY|[20]|List<Contract>.add(Object)
11:34:20.307 (307739819)|SYSTEM_METHOD_EXIT|[20]|List<Contract>.add(Object)
11:34:20.307 (307751120)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()
11:34:20.307 (307763939)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()
11:34:20.307 (307781526)|SYSTEM_METHOD_ENTRY|[23]|List<Contract>.size()
11:34:20.307 (307798445)|SYSTEM_METHOD_EXIT|[23]|List<Contract>.size()
11:34:20.307 (307817574)|SYSTEM_METHOD_ENTRY|[25]|List<Contract>.size()
11:34:20.307 (307831524)|SYSTEM_METHOD_EXIT|[25]|List<Contract>.size()
11:34:20.307 (307855976)|SYSTEM_METHOD_ENTRY|[25]|String.valueOf(Object)
11:34:20.307 (307872301)|SYSTEM_METHOD_EXIT|[25]|String.valueOf(Object)
11:34:20.307 (307891344)|SYSTEM_METHOD_ENTRY|[25]|System.debug(ANY)
11:34:20.307 (307904503)|USER_DEBUG|[25]|DEBUG|-ctr------->1
11:34:20.307 (307911558)|SYSTEM_METHOD_EXIT|[25]|System.debug(ANY)
11:34:20.307 (307971805)|DML_BEGIN|[26]|Op:Insert|Type:Contract|Rows:1
11:34:20.784 (784215005)|ENTERING_MANAGED_PKG|hoopla
11:34:20.802 (802867569)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Contract
11:34:20.892 (892987025)|WF_RULE_EVAL_BEGIN|Workflow
11:34:20.893 (893033020)|WF_CRITERIA_BEGIN|[Contract: 00000695 800S0000000m1GD]|Same Shipping Address|01QS00000001qNy|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:20.896 (896346251)|WF_RULE_FILTER|[Contract : Same as Billing Address equals true]
11:34:20.896 (896370200)|WF_RULE_EVAL_VALUE|0
11:34:20.896 (896376291)|WF_CRITERIA_END|false
11:34:20.896 (896397421)|WF_CRITERIA_BEGIN|[Contract: 00000695 800S0000000m1GD]|Contract is Active|01Q30000000Rowt|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:20.896 (896429301)|WF_RULE_FILTER|[Contract : Status equals Activated]
11:34:20.896 (896455467)|WF_RULE_EVAL_VALUE|Draft
11:34:20.896 (896460560)|WF_CRITERIA_END|false
11:34:20.896 (896478741)|WF_CRITERIA_BEGIN|[Contract: 00000695 800S0000000m1GD]|Ready to be Invoiced|01Q30000000RpxT|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:20.896 (896507135)|WF_RULE_FILTER|[Contract : Payment Status equals Ready to be Invoiced]
11:34:20.896 (896526984)|WF_RULE_EVAL_VALUE|6
11:34:20.896 (896531680)|WF_CRITERIA_END|true
11:34:20.961 (961511283)|WF_SPOOL_ACTION_BEGIN|Workflow
11:34:20.961 (961575284)|WF_RULE_INVOCATION|[Contract: 00000695 800S0000000m1GD]
11:34:20.961 (961590258)|WF_EMAIL_ALERT|Id=01W30000000Q6KD|CurrentRule:Ready to be Invoiced (Id=01Q30000000RpxT)
11:34:21.127 (1127129112)|WF_EMAIL_SENT|Template:00X300000023UIC|Recipients:tmurphy=gmh-inc.com@example.com yacosta=iqmediacorp.com@example.com |CcEmails:tmiller@gmh-inc.com
11:34:21.127 (1127175682)|WF_ACTION| Email Alert: 1;
11:34:21.127 (1127185290)|WF_RULE_EVAL_END
11:34:21.127 (1127980413)|WF_ACTIONS_END| Email Alert: 1;
11:34:21.127 (1127989440)|CODE_UNIT_FINISHED|Workflow:Contract
11:34:21.128 (1128150957)|DML_END|[26]
11:34:21.128 (1128402135)|SYSTEM_METHOD_ENTRY|[29]|List<Contract>.iterator()
11:34:21.128 (1128720309)|SYSTEM_METHOD_EXIT|[29]|List<Contract>.iterator()
11:34:21.128 (1128764192)|SYSTEM_METHOD_ENTRY|[29]|system.ListIterator.hasNext()
11:34:21.128 (1128789705)|SYSTEM_METHOD_EXIT|[29]|system.ListIterator.hasNext()
11:34:21.128 (1128935395)|SYSTEM_METHOD_ENTRY|[30]|Map<Id,Id>.put(Object, Object)
11:34:21.128 (1128990842)|SYSTEM_METHOD_EXIT|[30]|Map<Id,Id>.put(Object, Object)
11:34:21.129 (1129004478)|SYSTEM_METHOD_ENTRY|[29]|system.ListIterator.hasNext()
11:34:21.129 (1129017630)|SYSTEM_METHOD_EXIT|[29]|system.ListIterator.hasNext()
11:34:21.129 (1129042497)|SYSTEM_METHOD_ENTRY|[32]|Map<Id,Id>.size()
11:34:21.129 (1129065562)|SYSTEM_METHOD_EXIT|[32]|Map<Id,Id>.size()
11:34:21.129 (1129092791)|SYSTEM_METHOD_ENTRY|[32]|String.valueOf(Object)
11:34:21.129 (1129109528)|SYSTEM_METHOD_EXIT|[32]|String.valueOf(Object)
11:34:21.129 (1129130753)|SYSTEM_METHOD_ENTRY|[32]|System.debug(ANY)
11:34:21.129 (1129145491)|USER_DEBUG|[32]|DEBUG|Testmap size is 1
11:34:21.129 (1129152436)|SYSTEM_METHOD_EXIT|[32]|System.debug(ANY)
11:34:21.129 (1129192843)|SYSTEM_METHOD_ENTRY|[35]|Map<Id,Id>.keySet()
11:34:21.129 (1129256596)|SYSTEM_METHOD_EXIT|[35]|Map<Id,Id>.keySet()
11:34:21.130 (1130021695)|SOQL_EXECUTE_BEGIN|[34]|Aggregations:0|SELECT id, parentid, body, name FROM attachment WHERE parentid = :tmpVar1
11:34:21.166 (1166650637)|SOQL_EXECUTE_END|[34]|Rows:0
11:34:21.166 (1166780859)|SYSTEM_METHOD_ENTRY|[34]|String.valueOf(Object)
11:34:21.166 (1166839102)|SYSTEM_METHOD_EXIT|[34]|String.valueOf(Object)
11:34:21.166 (1166865796)|SYSTEM_METHOD_ENTRY|[34]|System.debug(ANY)
11:34:21.166 (1166891768)|USER_DEBUG|[34]|DEBUG|query data()
11:34:21.166 (1166906534)|SYSTEM_METHOD_EXIT|[34]|System.debug(ANY)
11:34:21.166 (1166958103)|SYSTEM_METHOD_ENTRY|[36]|Map<Id,Id>.keySet()
11:34:21.167 (1167007137)|SYSTEM_METHOD_EXIT|[36]|Map<Id,Id>.keySet()
11:34:21.167 (1167343897)|SOQL_EXECUTE_BEGIN|[36]|Aggregations:0|SELECT id, parentid, body, name FROM attachment
11:34:21.178 (1178521347)|SOQL_EXECUTE_END|[36]|Rows:0
11:34:21.178 (1178602491)|SYSTEM_METHOD_ENTRY|[36]|Database.QueryLocator.iterator()
11:34:21.178 (1178766655)|SYSTEM_METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator()
11:34:21.178 (1178780215)|SYSTEM_METHOD_EXIT|[7]|QueryLocatorIterator
11:34:21.178 (1178852030)|SYSTEM_METHOD_EXIT|[36]|Database.QueryLocator.iterator()
11:34:21.178 (1178872920)|SYSTEM_METHOD_ENTRY|[36]|Database.QueryLocatorIterator.hasNext()
11:34:21.178 (1178891952)|SYSTEM_METHOD_EXIT|[36]|Database.QueryLocatorIterator.hasNext()
11:34:21.178 (1178944784)|SYSTEM_METHOD_ENTRY|[43]|String.valueOf(Object)
11:34:21.178 (1178979364)|SYSTEM_METHOD_EXIT|[43]|String.valueOf(Object)
11:34:21.178 (1178995552)|SYSTEM_METHOD_ENTRY|[43]|System.debug(ANY)
11:34:21.179 (1179005086)|USER_DEBUG|[43]|DEBUG|attach is ()
11:34:21.179 (1179012430)|SYSTEM_METHOD_EXIT|[43]|System.debug(ANY)
11:34:21.179 (1179087927)|CUMULATIVE_LIMIT_USAGE
11:34:21.179 (1179087927)|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 2 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 1 out of 10000
Maximum CPU time: 142 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
11:34:21.179 (1179087927)|LIMIT_USAGE_FOR_NS|dsfs|
Number of SOQL queries: 4 out of 100
Number of query rows: 1 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
11:34:21.179 (1179087927)|LIMIT_USAGE_FOR_NS|hoopla|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
11:34:21.179 (1179087927)|CUMULATIVE_LIMIT_USAGE_END
11:34:21.179 (1179216985)|CODE_UNIT_FINISHED|CreateContractDocSignComp on DocuSign_Status trigger event AfterUpdate for [a0OS0000004Jl7V]
11:34:21.181 (1181179576)|EXECUTION_FINISHED
11:34:21.182 (1182142546)|EXECUTION_STARTED
11:34:21.182 (1182151333)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:01I30000002XM1b
11:34:21.190 (1190484790)|WF_RULE_EVAL_BEGIN|Workflow
11:34:21.190 (1190525302)|WF_CRITERIA_BEGIN|[DocuSign Status: DSX-0000155 a0OS0000004Jl7V]|Docusign Completed|01Q30000000RtKx|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:21.192 (1192477539)|WF_RULE_FILTER|[DocuSign Status : Envelope Status equals Completed]
11:34:21.192 (1192506106)|WF_RULE_EVAL_VALUE|Completed
11:34:21.192 (1192517746)|WF_CRITERIA_END|true
11:34:21.225 (1225183417)|WF_SPOOL_ACTION_BEGIN|Workflow
11:34:21.225 (1225228232)|WF_RULE_INVOCATION|[DocuSign Status: DSX-0000155 a0OS0000004Jl7V]
11:34:21.225 (1225243629)|WF_EMAIL_ALERT|Id=01W30000000Q7jT|CurrentRule:Docusign Completed (Id=01Q30000000RtKx)
11:34:21.282 (1282343359)|WF_EMAIL_SENT|Template:00X3000000244GC|Recipients:jdotson=iqmediacorp.com@example.com krussell=iqmediacorp.com@example.com |CcEmails:
11:34:21.282 (1282382778)|WF_ACTION| Email Alert: 1;
11:34:21.282 (1282387350)|WF_RULE_EVAL_END
11:34:21.282 (1282836664)|WF_ACTIONS_END| Email Alert: 1;
11:34:21.282 (1282844526)|CODE_UNIT_FINISHED|Workflow:01I30000002XM1b
11:34:21.284 (1284138117)|EXECUTION_FINISHED