• Maggie Farley 14
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Good Afternoon,

I have created a trigger in Sandbox but when I try to deploy it to production it will not work due to code coverage error. Do I need to add a test class? If so, how would I do that for this trigger? 

trigger setContractAttachment on Attachment (before insert) {
    List<Opportunity> opportunityList = new List<Opportunity>();
   set<Id> oppId = new set<Id>();
     for(Attachment att: Trigger.New){
        if(att.ParentId.getSobjectType() == Opportunity.SobjectType) {
            oppId.add(att.ParentId);
       }
}

//update the Opportunities
    opportunityList = [select id, Contract_Uploaded_Date__c from Opportunity where id in : oppId];
    if(opportunityList!=null && opportunityList.size()>0){
        for(Opportunity opp : opportunityList){
           opp.Contract_Uploaded_Date__c=Date.today();
        }
        update opportunityList;
    }
}
Hello,

I am trying to create a trigger to populate a Contract Uploaded Date on the Opportunity. I am new to triggers and keep getting erros on both the apex trigger and apex class. Can someone please help me? 

trigger setContractAttachment on Attachment (before insert) {
    List<Opportunity> listOpp = new List<Opportunity>();
     for(Attachment att: Trigger.New){
        if(att.ParentId.getSobjectType() == Opportunity.SobjectType) {
            oppId.add(att.ParentId);
            opp.Contract_Uploaded_Date__c=Date.today();
}

//update the Opportunities
    opportunityList = [select id, has_Attachment__c from Opportunity where id is : oppId];
    if(opportunityList!=null && opportunityList.size()>0){
        for(Opportunity opp : opportunityList){
            opp.has_Attachment__c = true;
        }
        update opportunityList;
    }


Test Class

Test Class
@isTest
 
public class ContractAttachmentTest {
    Opportunity = [Select id=;0062C0000022sfT]
    
    Attachment attachTest = new Attachment (Name= 'Test');
    attachTest.body = Blob.valueOf('')
    attachTest.ParentID = b.Id;
    attachTest.OwnerID = U.Id;
    insert attachTest;
        
}
 
Good Afternoon,

I have created a trigger in Sandbox but when I try to deploy it to production it will not work due to code coverage error. Do I need to add a test class? If so, how would I do that for this trigger? 

trigger setContractAttachment on Attachment (before insert) {
    List<Opportunity> opportunityList = new List<Opportunity>();
   set<Id> oppId = new set<Id>();
     for(Attachment att: Trigger.New){
        if(att.ParentId.getSobjectType() == Opportunity.SobjectType) {
            oppId.add(att.ParentId);
       }
}

//update the Opportunities
    opportunityList = [select id, Contract_Uploaded_Date__c from Opportunity where id in : oppId];
    if(opportunityList!=null && opportunityList.size()>0){
        for(Opportunity opp : opportunityList){
           opp.Contract_Uploaded_Date__c=Date.today();
        }
        update opportunityList;
    }
}
Hello,

I am trying to create a trigger to populate a Contract Uploaded Date on the Opportunity. I am new to triggers and keep getting erros on both the apex trigger and apex class. Can someone please help me? 

trigger setContractAttachment on Attachment (before insert) {
    List<Opportunity> listOpp = new List<Opportunity>();
     for(Attachment att: Trigger.New){
        if(att.ParentId.getSobjectType() == Opportunity.SobjectType) {
            oppId.add(att.ParentId);
            opp.Contract_Uploaded_Date__c=Date.today();
}

//update the Opportunities
    opportunityList = [select id, has_Attachment__c from Opportunity where id is : oppId];
    if(opportunityList!=null && opportunityList.size()>0){
        for(Opportunity opp : opportunityList){
            opp.has_Attachment__c = true;
        }
        update opportunityList;
    }


Test Class

Test Class
@isTest
 
public class ContractAttachmentTest {
    Opportunity = [Select id=;0062C0000022sfT]
    
    Attachment attachTest = new Attachment (Name= 'Test');
    attachTest.body = Blob.valueOf('')
    attachTest.ParentID = b.Id;
    attachTest.OwnerID = U.Id;
    insert attachTest;
        
}