• Racheal Dales 20
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I am not familiar on writing code, could anyone help me on by looking over my Trigger & Test Class?

I'm trying to create a Trigger to check a checkbox (the checkbox field name is Has_Attachment__c) on the Case object ( (specifically the Legal Help Desk record type = 0122M000001QR8xQAG)  every time an attachment is added, then I will use this to build a workflow to send an email to corresponding users every time the checkbox is true.

Within the Trigger where do I specify the Case Record Type?
trigger LegalCaseFileAttached on Attachment (before insert, before delete) 
{
if(trigger.isinsert){
List<Case> co = [select id from Case where id =: Trigger.New[0].ParentId];
If(co.size()>0)        
{            
co[0].Has_New_Case_Comment__c = True;            
update co;        
}
}


if(trigger.isdelete){

List<Case> co = [select id from Case where id =: Trigger.old[0].ParentId];        
If(co.size()>0)        
{            
co[0].Has_New_Case_Comment__c = false;            
update co;        
}
}
}
Also, I am stuck on trying to write the Test Class. I would greatly appreciate any help with this!
@isTest
public class LegalCaseFileAttachedTEST {
{
    static testMethod void attTriggerTest1()
    {
        test.startTest();      
        Case = new Case(Subject = 'Test Case', Status__c ='New');
        insert Case;   
        Attachment att = new Attachment(Name='textAtt', ParentId = Case.Id, body = Blob.valueOf('Some Text'), Description='TestAttachment');
        insert att;
        delete att;        
        test.stopTest();
    }
}
}
Also, I need to make sure this will work in Lightning.  Thanks so very much in advance for any help you can provide.
 
Hi there!

I hope somebody can help me ;) I altered this trigger to hopefully send an email alert when a new attachment is added to a case ( I am a new "developer"^^).

Now I need a Test Class for this Trigger to run in Production. I have no idea how to start as it's been awhile since I looked at code like this. 
trigger AttachmentLegalCaseTrigger on ContentDocumentLink (after insert) {	
	// 1. Get List of Object Ids you wish to notify on
	Set<Id> objectIds = new Set<Id>();
	
	// 2. Loop through list of attachments, and if attachment is associated to object you want to notify on, add Parent Id to objectIds set
	for(ContentDocumentLink a:trigger.new){
		 String keyPrefix = String.valueOf(a.LinkedEntityId).substring(0, 3);
		 
		 if(keyPrefix == '500'){
		 	objectIds.add(a.LinkedEntityId);
		 }
	}
	
	// 3. Get your objects you want to notify on, and set the Send Attachment Notification Email field to True 
        // This will to fire the workflow rule to send the email
	if(objectIds.size() > 0){
		List<Case> yourObjectList = [SELECT Id FROM Case WHERE Id IN :objectIds];
		
		for(Case obj:yourObjectList){
			obj.Send_Attachment_Notification_Email__c = true;
		}
		
		if(yourObjectList.size() > 0){
			update yourObjectList;
		}		
	}	  
}

Maybe its easy, but for me .. please help! :)  Thanks in advance!
 
Can anyone tell me if Delegated Authentication can be used in conjunction with an Okta SAML integration to specify which users participate in SSO via Okta? Thanks in advance!
Hi there!

I hope somebody can help me ;) I altered this trigger to hopefully send an email alert when a new attachment is added to a case ( I am a new "developer"^^).

Now I need a Test Class for this Trigger to run in Production. I have no idea how to start as it's been awhile since I looked at code like this. 
trigger AttachmentLegalCaseTrigger on ContentDocumentLink (after insert) {	
	// 1. Get List of Object Ids you wish to notify on
	Set<Id> objectIds = new Set<Id>();
	
	// 2. Loop through list of attachments, and if attachment is associated to object you want to notify on, add Parent Id to objectIds set
	for(ContentDocumentLink a:trigger.new){
		 String keyPrefix = String.valueOf(a.LinkedEntityId).substring(0, 3);
		 
		 if(keyPrefix == '500'){
		 	objectIds.add(a.LinkedEntityId);
		 }
	}
	
	// 3. Get your objects you want to notify on, and set the Send Attachment Notification Email field to True 
        // This will to fire the workflow rule to send the email
	if(objectIds.size() > 0){
		List<Case> yourObjectList = [SELECT Id FROM Case WHERE Id IN :objectIds];
		
		for(Case obj:yourObjectList){
			obj.Send_Attachment_Notification_Email__c = true;
		}
		
		if(yourObjectList.size() > 0){
			update yourObjectList;
		}		
	}	  
}

Maybe its easy, but for me .. please help! :)  Thanks in advance!
 
I am not familiar on writing code, could anyone help me on by looking over my Trigger & Test Class?

I'm trying to create a Trigger to check a checkbox (the checkbox field name is Has_Attachment__c) on the Case object ( (specifically the Legal Help Desk record type = 0122M000001QR8xQAG)  every time an attachment is added, then I will use this to build a workflow to send an email to corresponding users every time the checkbox is true.

Within the Trigger where do I specify the Case Record Type?
trigger LegalCaseFileAttached on Attachment (before insert, before delete) 
{
if(trigger.isinsert){
List<Case> co = [select id from Case where id =: Trigger.New[0].ParentId];
If(co.size()>0)        
{            
co[0].Has_New_Case_Comment__c = True;            
update co;        
}
}


if(trigger.isdelete){

List<Case> co = [select id from Case where id =: Trigger.old[0].ParentId];        
If(co.size()>0)        
{            
co[0].Has_New_Case_Comment__c = false;            
update co;        
}
}
}
Also, I am stuck on trying to write the Test Class. I would greatly appreciate any help with this!
@isTest
public class LegalCaseFileAttachedTEST {
{
    static testMethod void attTriggerTest1()
    {
        test.startTest();      
        Case = new Case(Subject = 'Test Case', Status__c ='New');
        insert Case;   
        Attachment att = new Attachment(Name='textAtt', ParentId = Case.Id, body = Blob.valueOf('Some Text'), Description='TestAttachment');
        insert att;
        delete att;        
        test.stopTest();
    }
}
}
Also, I need to make sure this will work in Lightning.  Thanks so very much in advance for any help you can provide.
 
Can anyone tell me if Delegated Authentication can be used in conjunction with an Okta SAML integration to specify which users participate in SSO via Okta? Thanks in advance!