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