You need to sign in to do that
Don't have an account?

Help w/ Implementation
Hi,
I am very new to Apex and need some help. I created an Apex trigger to run on a custom object that checks a box when a file is uploaded and unchecks a box when the file is removed. I manually tested it which worked and uploaded it to my production org, but found out that my code needs 75% testing coverage. I created a Test class but I'm getting 0% code coverage. Here is my Trigger:
And here is my Test Class:
Once complete will I also have to reupload my code into my production org?
Thanks!
I am very new to Apex and need some help. I created an Apex trigger to run on a custom object that checks a box when a file is uploaded and unchecks a box when the file is removed. I manually tested it which worked and uploaded it to my production org, but found out that my code needs 75% testing coverage. I created a Test class but I'm getting 0% code coverage. Here is my Trigger:
trigger imaUp on Attachment (after insert, after update, after delete) { if(trigger.isInsert || trigger.isUpdate){ List<IMA__c> co = [select id, Uploaded__c from IMA__c where id =: Trigger.New[0].ParentId]; if(co.size()>0) { co[0].Uploaded__c = true; update co; } } if(trigger.isDelete) { List<IMA__c> co1 = [select id, Uploaded__c from IMA__c where id =: Trigger.old[0].ParentId]; if(co1.size()>0) { co1[0].Uploaded__c = false; update co1; } } }
And here is my Test Class:
@isTest public class imaUpTest { @isTest static void test_method_one() { IMA__c co = new IMA__c(); co.Date_Sent__c = Date.today(); co.Date_Signed__c = Date.today(); co.Entity__c = 'Test'; co.Status__c = 'Signed'; co.Uploaded__c = TRUE; insert co; Attachment attach = new Attachment(); attach.Name = 'TestFile'; attach.parentId = co.id; insert attach; } }
Once complete will I also have to reupload my code into my production org?
Thanks!
check below link to create body using some test string and then assign body and insert attachment.
http://theblogreaders.com/how-to-convert-from-string-to-blob-using-apex-class/#.V0NEMPkrJpg
In the test class you can alsp update and delete attachment to get 100% coverage
All Answers
check below link to create body using some test string and then assign body and insert attachment.
http://theblogreaders.com/how-to-convert-from-string-to-blob-using-apex-class/#.V0NEMPkrJpg
In the test class you can alsp update and delete attachment to get 100% coverage
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
Stack Trace: Class.imaUpTest.test_method_one: line 10, column 1