• Shannon Andreas 1
  • NEWBIE
  • 135 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 27
    Questions
  • 80
    Replies
Can anyone help me with test code for the following trigger?

trigger addAccount on Lead (before Insert, before Update)
{
 
 List<string> companies=new list<string>();
 
  For (lead l:trigger.new){
    companies.add(l.company);
  }
 
  List<Account> leadAccountIds=[Select Id, OwnerId, Name FROM Account WHERE Name IN: companies];
 
   Map<String, Id> acctNameId=new Map<String, Id>();
   Map<String, Id> acctNameOwner=new Map<String, Id>();
 
  For (Account a:leadAccountIds){
    acctNameId.put(a.name,a.Id);
    acctNameOwner.put(a.name,a.ownerId);
  }
 
  For (Lead l2:trigger.new){
    if(acctNameId.containsKey(l2.company)){
      l2.Account_Name__c=acctNameId.get(l2.company);
      l2.ownerId=acctNameOwner.get(l2.company);
    }
  }
}

Thank you!!

Shannon
Hello All!

I am using this formula to calculate the term in months from effective date to end date. Works great if the months are different. However, it appears to be adding a month if my effective and end dates are in the same month.

e.g. Effective Date: 11/23/2015
       End DAte: 11/22/2016
Calculating 13 month term.


Anyone know how I can resolve?

Data Type Formula    
Decimal Places 0    
IF(NOT(ISBLANK(Service_End_Date__c)) && NOT(ISBLANK(Service_Effective_Date__c)) 
,(((YEAR(Service_End_Date__c ) - YEAR(Service_Effective_Date__c ) - 1) *12) + (12 - MONTH(Service_Effective_Date__c) +1) + MONTH(Service_End_Date__c )) 
, null 
)
Hello!

I was wondering if someone could help me out with a formula.

I need a formula that calculates the future date of a contract expiration.So the case goes like this:

Effective Date of contract year 1 = Service_Effective_Date__c
End date of contract year 1 = 12 months from Service_Effective_Date__c
Effective Date of contract year 2 = End date of Contract year 1 + 1 day
End Date of contract year 2 = 12 months from Effective Date of contract year 2
Effective Date of contract year 3 = End date of Contract year 2 + 1 day
End Date of contract year 3 = 12 months from Effective Date of contract year 3

Of course, I tried adding 365 days, but as you all know, that won't account for leap years and varying numbers of days in a month.

There is a contract term field which indicates the term in months of a contract if that would be easier to use.

Any help is appreciated.

Shannon
 
Hello!

I need some assistance.

I have created a formula that will input a date value from an opportunity record (CloseDate) into a custom field on the Contract record (Opportunity_Close_Date__c). The formula is Opportunity_Name__r.CloseDate on the contract record field.

The problem is that if the opportunity close date is changed on the Opporunity, it changes on the contract record. I am wondering if there is a way to record the value only as static text on the contract record? I don't want the value to change once it has been input into the contract.

Thanks!
Hello all!

I am trying to deploy a change set to deactivate one of my triggers in production. When I try to validate or deploy, i get the following error:

System.QueryException: List has no rows for assignment to SObject 
Stack Trace: Class.CreateContractWAttachmentTrgTest.attachmentTest: line 20, column 1

I read that I can comment out the test class, but I am having trouble with it because I have never done this. Can you tell me how I can do this easily? I tried using /* and */ at the beginning of the test class and the end, respectively. I am getting the following error when I try to save:

Error: Compile Error: unexpected token: '<EOF>' at line 30 column 0

Thanks!

Shannon
Hello!

I am trying to find a way to prefill fields on the Quote record with field values from the Oppty. The standard quote button pulls in the oppty and acct names automatically as it has a parent-child relationship. It also pulls in the Quote Line Items that are synced from the Products Line Items on the oppty.

I don't have anything to show here because I am not sure what to use to get this done. I was thinking javascript button, but then thought it might take apex code and a possible vf page. All of which I am pretty inexperienced with. I can probably wing the javascript as I found some basic code that might work (although I am having a hard time referencing the opportunity id and account id of the oppty to the Quote).

Can someone point me in the right direction? I would need a response that is somewhat detailed on how I can approach this. 

Thanks for your help!

Shannon
Hello!

Can someone help me with a trigger? I have it together, but there is an issue with the attachment part. It is not attaching. Here is the trigger:

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,dsfsid__c = dsfs.id);
             ctr.add(c);
        }
      }
      if(ctr.size() > 0)
      {
             System.debug('-ctr------->'+ctr.size());
             insert ctr;
      }
      
        for(contract con : ctr){
         testmap.put(con.dsfsid__c, con.id);
      }
      system.debug('Testmap size is '+testmap.size());
      
      system.debug('query data'+[select id,parentid,body,name from attachment where parentid in :
      testmap.keyset()]);
        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);
      }
      }
      system.debug('attach is '+attach);
      insert attach;
      
      }

Thanks so much!
Hello Friends!

I need your expertise here.

I am trying to find the average number of demos per month via matrix or summary report.

We are trying to find 1.) demos completed per month by lead source and 2.) the average number of demos completed (1 demo complete = 1 Oppty) per rep per month, based on the current number of months. Here is the first part of the requested report:
User-added image

I now need to find the average per month, per user for each user. It does not have to be by lead source.

Anyone have any ideas?

Thanks,

Shannon
 
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;
      
      }

 

Hello Friends,

I need assistance writing a trigger that will allow me to copy an attachment from a DocuSign object to a contract.

Just some background...

I have a trigger that creates a contract when DocuSign_Status (object) = Completed. The DocuSign workflow adds the attachment to the already created DocuSign_Status record when signing is completed; which fires the trigger to create the contract. Unfortunately, the trigger does not include copying of the attachment. 

I need to add in copying of the attachment to the current trigger or write a new one, but I need help! I have researched and seen many ways of doing something similar, but not sure it is what I need. I am attaching my trigger below. Any help would be greatly appreciated.

Thanks!  Shannon

trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
    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;
      }     
}

I have created a trigger that will create a contract when a DocuSign is completed. I also need the trigger (or another trigger which seems wrong to me) to move the attachment.

Process is when sending to DocuSign, a DocuSign Status record is created. When the Envelope Status changes to "Completed", the contract is created. IN addition to creating the contract, I need the trigger to "copy" the completed document attachment from the DocuSign Status record to the new contract.

Here is my trigger:

trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
    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!

Shannon
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



 
Can someone help me with this trigger/test class. I am trying to create a contract when the status of a DocuSign = Completed.

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;
      }     
}



@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'));
    insert o;
    
       dsfs__DocuSign_Status__c  dsfs = new dsfs__DocuSign_Status__c(
       dsfs__Company__c = o.AccountId,
       dsfs__Opportunity__c = o.Name,
       dsfs__Envelope_Status__c = 'Completed',
       dsfs__DocuSign_Envelope_ID__c = '1001A123-1234-5678-1D84-F8D44652A382',
       dsfs__Subject__c = 'Document for eSignature');
    insert dsfs;
 Test.StartTest();
       
            
            List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
                 //System.assertNotEquals(1stContr,null);
                 
        Test.StopTest();
       
      }
}

Thanks!

Shannon
Hello!

I have created a trigger that will create a contract when the docusign status = Completed. 

I wrote a test class and am getitng the following error:
Error: Compile Error: Invalid type: dsfs_DocuSign_Status__c at line 19 column 42

I know there will be more as well. Wondering if anyone can help me with the test class?

Trigger:
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;
      }     
}

Test Class:
@isTest
private class TestCreateContractDocSignCompTrigger 
{
    static testMethod void validateCreateContractDocSignComp() 
    {   
       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'));
    insert o;
    
      dsfs_DocuSign_Status__c dsfs = new dsfs_DocuSign_Status__c(
      Name = 'DSX-1000000',
      dsfs__Company__c = o.AccountId,
      dsfs__Opportunity__c = o.Id,
      dsfs__Envelope_Status__c = 'Completed');
    insert dsfs;
       
       Test.StartTest();
            
            List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
                 //System.assertNotEquals(1stContr,null);
                 
        Test.StopTest();
       
      }
}

Any help is greatly appreciated! Shannon
Wrote a trigger. Getting 33% code coverage and cannot deploy to production. Any help in making my test class code better?

Thanks!

trigger CreateContract on Opportunity (after insert) {
    List<Contract> ctr = new List<Contract>();
    
      for(Opportunity o : Trigger.new) {
        if(o.Ready_for_Contract__c == true) {
          Contract c = new Contract(Name = o.Name,
             Status = 'Draft',
             Total_Contract_Value__c = o.Amount,
             StartDate = o.Contract_Start_Date__c,
             Payment_Status__c = 'Ready to be Invoiced',
             Account = o.Account,
             Opportunity_Name__c = o.Id);
         ctr.add(c);
         }
      insert ctr;
      }
}


TEST Class
@isTest
private class TestClassCreateContractTrigger 
{
    static testMethod void validateCreateContract() 
    {   
       Account a = new Account(
       Name = 'Test Account');
    insert a;

       Opportunity o = new Opportunity(
       Name = 'Test Opp',
       CloseDate = System.Today(),
       AccountId = a.Id,
       StageName = 'Signed / Closed Sale',
       Amount = decimal.valueof('6995'));
    insert o;
    
       Contract c = new Contract(
            Name='Test Contract',
            Status = 'Draft',
            Total_Contract_Value__c = o.Amount,
            StartDate = System.Today(),
            Payment_Status__c = 'Ready to be Invoiced',
            AccountId = o.AccountId,
            Opportunity_Name__c = o.Id);
       insert c;
       
      }
}
 
I have a trigger and am trying to write a test class (see below). The trigger is not working...I have asked for help with no resolution. I am asking again for help with the trigger as well as test class (which is not working either). I think my issue is with the Account ID and Opportunity ID part. 

All I am trying to do is have a contract created when a checkbox on the oppty is checked. 

Please see previous post: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BTEhIAO

TRIGGER:

trigger CreateContract on Opportunity (after insert) {
 private List<Contract> ctr = new List<Contract>();
 
  for(Opportunity o : Trigger.new) {
    if(o.Ready_for_Contract__c == true) {
      Contract c = new Contract(Name = o.Name,
                                Status = 'Draft',
                                Total_Contract_Value__c = o.Total_Sales_Price_of_Products__c,
                                StartDate = o.Contract_Start_Date__c,
                                Payment_Status__c = 'Ready to Be Invoiced',
                                AccountId = o.AccountId,
                                Opportunity_Name__c = o.Id);
        ctr.add(c); 
      }
      insert ctr;
     }    
}

TEST Class:

@isTest
private class TestClassCreateContractTrigger 
{
    static testMethod void validateCreateContract() 
    {       
       Contract c = new Contract(
            Name='Test Account',
            Status = 'Activated',
            Total_Contract_Value__c = decimal.valueof('6995'),
            StartDate = System.Today(),
            Payment_Status__c = 'Ready to Be Invoiced',
            AccountId = Opportunity.AccountId,
            Opportunity_Name__c = Opportunity.Id);
       insert c;
       
      }
}

Thanks in advance for your help!!

Shannon
So...I created my almost very first trigger...it's not firing. Please help. I pieced together code from different sources and thought I was on the right track...hmmmm

Trying to create a contract when the checkbox "Ready for Contract" is checked. Do I need the opportunity ID as well? Not sure why this is not working. Thanks in advance for help. Shannon

trigger CreateContract on Opportunity (before insert) {
 private List<Contract> ctr = new List<Contract>();
  
  for(Opportunity o : Trigger.new) {
    if(o.Ready_for_Contract__c = true) {
      Contract c = new Contract(Id = o.Account.Id,
                                Name = o.Name,
                                Status = 'Activated',
                                Total_Contract_Value__c = o.Total_Sales_Price_of_Products__c,
                                StartDate = o.Contract_Start_Date__c,
                                Payment_Status__c = 'Ready to Be Invoiced');
      ctr.add(c);
      }
      insert ctr;
      }
      }
So, I need a way for Salesforce to automatically create a contract record when we receive a DocuSign back as Complete.

Today, we have to create a Quote, fill out the fields, then click on the Loop Plus button to create a DocuSign. When we are ready to send the contract, we have to create a contract record, then click on the Loop Plus botton on the contract to create a DocuSign. The problem is that we have contracts out there that are not signed and create bunch of extra work for our contract reviewer in having to reach out the rep to delete the contract record. I could create an email alert that goes out after so much time stating that the contract is still in draft. However, we would really like to have the contract auto-created when we receive a completely signed DocuSign. We would also like the fields to auto-populate with necessary information and have certain picklist field values selected (these picklists trigger email alerts to accounting and training). 

So here is what we have today as a process:

1.) Quote record created from related list on Opportunity
2.) Contract record created from related list on Quote 
  a.) Contract record fields are filled in. Payment Status is automatically set to "Incomplete" and Contract Status is set to "Draft".
  b.) Contract document is prepared using Loop Plus custom button.
  c.) User clicks on link that will send document using DocuSign.
  d.) Document attaches to the Contract and Oppty records as a pdf.
3.) Document is signed by customer. Details show up in the Oppty in related list "DocuSign Status"
4.) Document is signed by Company. Details show up in the Oppty in related list "DocuSign STatus".
5.) Document is now status = Completed

Here is what we want:

1.) Contract document (Loop PLus/DocuSign) can be created from either Quote or Opportunity.
2.) When DocuSign is Completed, the contract record is created and attaches to record.
  a.) Contract fields autopopulate with fields from Oppty or Quote,
  b.) Status = Activated
  c.) Payment Status = Ready to be Invoiced

Sorry this is so long winded. Just wanted to be sure to cover any questions.

I was considering using Process Builder or Flows, but not really sure which one makes sense for this scenario. Also, I am a novice with both and Builder seems to be a little more complex than Flows.

Any help is appreciated,

Thanks, Shannon
Trying to create a custom list button, "Generate Contract" that will pre-populate fields from the Quote object to the Contract object through URL. I can get everything to pass except for the lookup fields: Opportunity Name and Account Name.

I have tried this 100 different ways! Here is what I have now for the custom button created on the contract and placed on a related list in the quote::

/800/e?ctrc7={!Opportunity.AccountId}&
CF00NS0000001SGhG={!Opportunity.Id}&
retURL={!Quote.Id}

Here is the result:

https://cs1.salesforce.com/800/e?ctrc7=&CF00NS0000001SGhG=&retURL=0Q0S0000000Dw8F

Just in case anyone is wondering, I did not use the account name and opportunity listed on the Quote because I cannot find the field names when I "view source". I think that I read somewhere that is because those fields are pulled from the opportunity. So I have tried both the Opportunity and Account IDs, Names, etc.

Please help! I have been working on this for weeks and no one seems to be able to help.

Thanks in advance,

Shannon
 
Was not sure where to post this question, but thought someone would at least be able to point me in the right direction.

I need a way to create a dashboard/report that shows our reps individual goals versus actuals. For example, we need to set individual performance goals such as "# of Demos Completed", "# of Demos Scheduled", etc. Reps are required to use a custom checkbox field within an opportunity when a demo has been completed or scheduled. 

Does anyone know how I can make this happen? Is there an AppExchange app I can look at or is there something I can build with a custom object?

Please any advice is welcome.

Thanks in advance for your assistance.

Shannon
Hello!

I was wondering if someone could help me out with a formula.

I need a formula that calculates the future date of a contract expiration.So the case goes like this:

Effective Date of contract year 1 = Service_Effective_Date__c
End date of contract year 1 = 12 months from Service_Effective_Date__c
Effective Date of contract year 2 = End date of Contract year 1 + 1 day
End Date of contract year 2 = 12 months from Effective Date of contract year 2
Effective Date of contract year 3 = End date of Contract year 2 + 1 day
End Date of contract year 3 = 12 months from Effective Date of contract year 3

Of course, I tried adding 365 days, but as you all know, that won't account for leap years and varying numbers of days in a month.

There is a contract term field which indicates the term in months of a contract if that would be easier to use.

Any help is appreciated.

Shannon
 
Hello!

Can someone help me with a trigger? I have it together, but there is an issue with the attachment part. It is not attaching. Here is the trigger:

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,dsfsid__c = dsfs.id);
             ctr.add(c);
        }
      }
      if(ctr.size() > 0)
      {
             System.debug('-ctr------->'+ctr.size());
             insert ctr;
      }
      
        for(contract con : ctr){
         testmap.put(con.dsfsid__c, con.id);
      }
      system.debug('Testmap size is '+testmap.size());
      
      system.debug('query data'+[select id,parentid,body,name from attachment where parentid in :
      testmap.keyset()]);
        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);
      }
      }
      system.debug('attach is '+attach);
      insert attach;
      
      }

Thanks so much!
Can anyone help me with test code for the following trigger?

trigger addAccount on Lead (before Insert, before Update)
{
 
 List<string> companies=new list<string>();
 
  For (lead l:trigger.new){
    companies.add(l.company);
  }
 
  List<Account> leadAccountIds=[Select Id, OwnerId, Name FROM Account WHERE Name IN: companies];
 
   Map<String, Id> acctNameId=new Map<String, Id>();
   Map<String, Id> acctNameOwner=new Map<String, Id>();
 
  For (Account a:leadAccountIds){
    acctNameId.put(a.name,a.Id);
    acctNameOwner.put(a.name,a.ownerId);
  }
 
  For (Lead l2:trigger.new){
    if(acctNameId.containsKey(l2.company)){
      l2.Account_Name__c=acctNameId.get(l2.company);
      l2.ownerId=acctNameOwner.get(l2.company);
    }
  }
}

Thank you!!

Shannon
Hello All!

I am using this formula to calculate the term in months from effective date to end date. Works great if the months are different. However, it appears to be adding a month if my effective and end dates are in the same month.

e.g. Effective Date: 11/23/2015
       End DAte: 11/22/2016
Calculating 13 month term.


Anyone know how I can resolve?

Data Type Formula    
Decimal Places 0    
IF(NOT(ISBLANK(Service_End_Date__c)) && NOT(ISBLANK(Service_Effective_Date__c)) 
,(((YEAR(Service_End_Date__c ) - YEAR(Service_Effective_Date__c ) - 1) *12) + (12 - MONTH(Service_Effective_Date__c) +1) + MONTH(Service_End_Date__c )) 
, null 
)
Hello!

I need some assistance.

I have created a formula that will input a date value from an opportunity record (CloseDate) into a custom field on the Contract record (Opportunity_Close_Date__c). The formula is Opportunity_Name__r.CloseDate on the contract record field.

The problem is that if the opportunity close date is changed on the Opporunity, it changes on the contract record. I am wondering if there is a way to record the value only as static text on the contract record? I don't want the value to change once it has been input into the contract.

Thanks!
Hello all!

I am trying to deploy a change set to deactivate one of my triggers in production. When I try to validate or deploy, i get the following error:

System.QueryException: List has no rows for assignment to SObject 
Stack Trace: Class.CreateContractWAttachmentTrgTest.attachmentTest: line 20, column 1

I read that I can comment out the test class, but I am having trouble with it because I have never done this. Can you tell me how I can do this easily? I tried using /* and */ at the beginning of the test class and the end, respectively. I am getting the following error when I try to save:

Error: Compile Error: unexpected token: '<EOF>' at line 30 column 0

Thanks!

Shannon
Hello!

I am trying to find a way to prefill fields on the Quote record with field values from the Oppty. The standard quote button pulls in the oppty and acct names automatically as it has a parent-child relationship. It also pulls in the Quote Line Items that are synced from the Products Line Items on the oppty.

I don't have anything to show here because I am not sure what to use to get this done. I was thinking javascript button, but then thought it might take apex code and a possible vf page. All of which I am pretty inexperienced with. I can probably wing the javascript as I found some basic code that might work (although I am having a hard time referencing the opportunity id and account id of the oppty to the Quote).

Can someone point me in the right direction? I would need a response that is somewhat detailed on how I can approach this. 

Thanks for your help!

Shannon
Hello!

Can someone help me with a trigger? I have it together, but there is an issue with the attachment part. It is not attaching. Here is the trigger:

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,dsfsid__c = dsfs.id);
             ctr.add(c);
        }
      }
      if(ctr.size() > 0)
      {
             System.debug('-ctr------->'+ctr.size());
             insert ctr;
      }
      
        for(contract con : ctr){
         testmap.put(con.dsfsid__c, con.id);
      }
      system.debug('Testmap size is '+testmap.size());
      
      system.debug('query data'+[select id,parentid,body,name from attachment where parentid in :
      testmap.keyset()]);
        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);
      }
      }
      system.debug('attach is '+attach);
      insert attach;
      
      }

Thanks so much!
Hello Friends!

I need your expertise here.

I am trying to find the average number of demos per month via matrix or summary report.

We are trying to find 1.) demos completed per month by lead source and 2.) the average number of demos completed (1 demo complete = 1 Oppty) per rep per month, based on the current number of months. Here is the first part of the requested report:
User-added image

I now need to find the average per month, per user for each user. It does not have to be by lead source.

Anyone have any ideas?

Thanks,

Shannon
 
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;
      
      }

 

Hello Friends,

I need assistance writing a trigger that will allow me to copy an attachment from a DocuSign object to a contract.

Just some background...

I have a trigger that creates a contract when DocuSign_Status (object) = Completed. The DocuSign workflow adds the attachment to the already created DocuSign_Status record when signing is completed; which fires the trigger to create the contract. Unfortunately, the trigger does not include copying of the attachment. 

I need to add in copying of the attachment to the current trigger or write a new one, but I need help! I have researched and seen many ways of doing something similar, but not sure it is what I need. I am attaching my trigger below. Any help would be greatly appreciated.

Thanks!  Shannon

trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
    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;
      }     
}