• Flexy
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi Everyone, 
I have this Apex Trigger in Sandbox that check if there is an attachment when Grant is Awarded, I need a test class to Deploy it in the production environment,any help..

trigger AttachmentValidation on Opportunity (before update) {
    
    Set<Id> OpptyIdSet = new Set<Id>();
    
    for(Opportunity oppty : Trigger.new){
        //Validation of the fields
        if(oppty.StageName == 'Grant Awarded'){
              OpptyIdSet.add(oppty.id);          
        }
    }
    
    for(Opportunity oppty : [SELECT id,name,(SELECT Id, LinkedEntityId, ContentDocumentId FROM ContentDocumentLinks) FROM Opportunity WHERE id in:OpptyIdSet]){
        
        if(oppty.ContentDocumentLinks.isEmpty()){
            Trigger.newMap.get(oppty.Id).addError('A Grant Agreement attachment is required. If New Opportunity Stage is Grant Awarded/Completed/Certain, to attach, change the stage to anything other than Grant Awarded/Completed/Renewal - Certain and then save it. Afterwards, edit the opp and change the stage as desired and add the attachment.');
        }
    }
}


Thank you.
 
  • January 17, 2021
  • Like
  • 0
Hi Everyone, 
I have this Apex Trigger in Sandbox that check if there is an attachment when Grant is Awarded, I need a test class to Deploy it in the production environment,any help..

trigger AttachmentValidation on Opportunity (before update) {
    
    Set<Id> OpptyIdSet = new Set<Id>();
    
    for(Opportunity oppty : Trigger.new){
        //Validation of the fields
        if(oppty.StageName == 'Grant Awarded'){
              OpptyIdSet.add(oppty.id);          
        }
    }
    
    for(Opportunity oppty : [SELECT id,name,(SELECT Id, LinkedEntityId, ContentDocumentId FROM ContentDocumentLinks) FROM Opportunity WHERE id in:OpptyIdSet]){
        
        if(oppty.ContentDocumentLinks.isEmpty()){
            Trigger.newMap.get(oppty.Id).addError('A Grant Agreement attachment is required. If New Opportunity Stage is Grant Awarded/Completed/Certain, to attach, change the stage to anything other than Grant Awarded/Completed/Renewal - Certain and then save it. Afterwards, edit the opp and change the stage as desired and add the attachment.');
        }
    }
}


Thank you.
 
  • January 17, 2021
  • Like
  • 0