You need to sign in to do that
Don't have an account?
Carolyn juliana
How to write Test class to test a field on an attachment or file insert?
Below is the trigger update a field on an attachment or file insert , can some one suggest a test class for this trigger?
Can some one please help in writing a @isTest class for below trigger to achieve 100 % code completion
here is the class
Thanks in Advance,
Carolyn
Can some one please help in writing a @isTest class for below trigger to achieve 100 % code completion
trigger ContentDocumentLinkTrigger on ContentDocumentLink (after insert) { if(trigger.isAfter) { if(trigger.isInsert) { ContentDocumentLinkTriggerHandler.onAfterInsert(trigger.new); } } }
here is the class
public class ContentDocumentLinkTriggerHandler { public static void onAfterInsert(list<ContentDocumentLink> lstCntLinks) { set<Id> setTaskIds = new set<Id>(); list<task> lstTask=new list<task>(); Id recordTypeId = Schema.SObjectType.Task.getRecordTypeInfosByName().get('Task_Record_Type').getRecordTypeId(); for(ContentDocumentLink clIterator : lstCntLinks) { setTaskIds.add(clIterator.LinkedEntityId);//Set all task id } if(!setTaskIds.isEmpty()) { lstTask= [SELECT Id, Name,Attachment_Indicator__c FROM task WHERE Id IN :setTaskIds and recordtypeid=: recordTypeId ]; //Get all the task } for(task varTsk: lstTask){ varTsk.Attachment_Indicator__c=true;//Set Attachment Indicator Flag true } if(lstTask.size()>0){ update lstTask; //update task } } }
Thanks in Advance,
Carolyn
In your apex class line 13, SOQL query remove name as there is no such standard field name on Task and it will give error. Try using below test class for 100% coverage.
Hope this helps! Please mark as solved if it does.
Thanks
All Answers
In your apex class line 13, SOQL query remove name as there is no such standard field name on Task and it will give error. Try using below test class for 100% coverage.
Hope this helps! Please mark as solved if it does.
Thanks
The line 6 in the test class is similar to line 6 in your apex classto fetch the record id of "task record type". The error is because it couldn't find and record type on task object with that developername. If your org has record type with developer name Task_Record_Type on task it should not give you this error. However try replacing line 6 in test class with below line as its working in your apex class if you still get the error, in your query editor try execting below SOQL query if the above query doesn't result any record then there seem to be issue with developer name for the Task record type. Further to fix that and to know correct developer name and name of the record type try executing below:
Hope this helps!
Thanks
Now my test clas ran fine with below code ,but the problem is Code coverage is still Zero
Try replacing line 6 in your apex class with below and post the screenshots please.
Thanks
Apex Trigger "ContentDocLinkTrigger"
Apex Class "ContentDocumentLinkTriggerHandler"
Apex test class "ContentDocLinkTriggerhanlderTest"
Thank you so much Sravani
Carolyn
Thanks,
Sarvani