You need to sign in to do that
Don't have an account?
Trigger to roll up information from Docusign Status to Change Opp Status
Howdy Folks! I am trying to write a trigger that will work like a roll up summary field. I have to run this through a trigger as I cannot create a master detail relationship with a managed custom object. This is using docusign.
The use case is this. When a doc is marked as completed in the custom object Docusign status (dsfs__DocuSign_Status__c). I need to get a count of items either completed or Denied and use that data to manage the Opportunity stage.
If status =complete, stage = Closed Won
if Status=Denied, Stage = Closed Lost
Has anyone run into this issue?! I cannot believe I am the first one to need this automation. Thanks folks!
Hi Kevin,
As per my understanding of your scenario
Thsi is trhe Sample Trigger
trigger Status on Docusign__c(After Insert,After Update) {
Map<ID,String> mapoppid=new Map<ID,String>();
List<ID> OppIDs = new List<ID>();
if(Trigger.isInsert || Trigger.isUpdate)
for(Docusign__c ds:Trigger.new)
{
system.debug('###########'+ds.Status__c);
if(ds.Status__c=='complete'){
mapoppid.put(ds.Opportunity__c,'Closed Won');
}
else if(ds.Status__c=='Denied'){
mapoppid.put(ds.Opportunity__c,'Closed Lost');
}
List<Opportunity> Updateopp=[SELECT Id,StageName FROM Opportunity WHERE Id IN:mapoppid.keyset()];
for(Opportunity opp:Updateopp)
{
Opp.StageName=mapoppid.get(Opp.Id);
system.debug('###########'+Opp.StageName);
}
Update Updateopp;
}
}
You can make modification as per your requirement ...
Thanks
Srinivas
All Answers
Hi,
your question is not clear.
for e.g lets say i have 5 records of dsfs__DocuSign_Status__c and out of 5 only status of one record is complete, in this case should we set the status of opportunity to Closed Won or is there any specific number of record with complete status.
Hi Kevin,
As per my understanding of your scenario
Thsi is trhe Sample Trigger
trigger Status on Docusign__c(After Insert,After Update) {
Map<ID,String> mapoppid=new Map<ID,String>();
List<ID> OppIDs = new List<ID>();
if(Trigger.isInsert || Trigger.isUpdate)
for(Docusign__c ds:Trigger.new)
{
system.debug('###########'+ds.Status__c);
if(ds.Status__c=='complete'){
mapoppid.put(ds.Opportunity__c,'Closed Won');
}
else if(ds.Status__c=='Denied'){
mapoppid.put(ds.Opportunity__c,'Closed Lost');
}
List<Opportunity> Updateopp=[SELECT Id,StageName FROM Opportunity WHERE Id IN:mapoppid.keyset()];
for(Opportunity opp:Updateopp)
{
Opp.StageName=mapoppid.get(Opp.Id);
system.debug('###########'+Opp.StageName);
}
Update Updateopp;
}
}
You can make modification as per your requirement ...
Thanks
Srinivas
Thank you very much! This was just what I was looking for! Currently I am writing it as 2 triggers but this should consolidate that and I would only have to write one Test class as opposed to 2 of them. Thank you very much! Just for fun, would you happen to have an example of what my class should look like? I always get this far and then fail in deployment as I am not very good at putting the test classes together. Thank you Srinivas!
i make a trigger for this but i am not getting proper out comes.
this is my trigger please help me to over come this problem.........
trigger checkStage on dsfs__DocuSign_Status__c (After Insert,After Update) {
List<Id> oppIds = new List<Id>();
for(dsfs__DocuSign_Status__c dc:trigger.new){
if(dc.dsfs__Envelope_Status__c =='complete'){
oppIds.add(dc.dsfs__Opportunity__c);
}
}
List<Opportunity> oppList = [select StageName from Opportunity where id in:oppIds];
List<Opportunity> oppListnew = new List<Opportunity>();
for(Opportunity op : oppList){
op.StageName='Closed Won';
oppListnew.add(op);
}
update oppListnew;
}