You need to sign in to do that
Don't have an account?
Steve Loudermilk
Test class for attachment help
I am basically writing that attachment ID to a custome field so I can display it on a page. I have the trigger written which I will add below, but I am having trouble with the test class. I went down the pat of "loading" in a record an attachment, but haven't managed to get coverage yet. If someoen could help me out I would be very appreciative.
Thanks in advance,
Milk
Thanks in advance,
Milk
trigger MoveAttachmentIDforFormula on Attachment (after insert) { Map<Id, Id> mapCSId = new map<Id, Id>(); List<InspectTHIS__Applied_Questionnaire__c> dct = new List<InspectTHIS__Applied_Questionnaire__c>(); String objectName = ''; for(Attachment atc: trigger.new){ String myIdPrefix = string.valueOf(atc.ParentId).substring(0,3); Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); for(Schema.SObjectType stype : gd.values()){ Schema.DescribeSObjectResult r = stype.getDescribe(); String prefix = r.getKeyPrefix(); if(prefix!=null && prefix.equals(myIdPrefix)){ objectName = r.getName(); } } if(objectName == 'InspectTHIS__Applied_Questionnaire__c'){ mapCSId.put(atc.ParentId, atc.id); } } if(!mapCSId.isEmpty()){ List<InspectTHIS__Applied_Questionnaire__c> lstdct = [select id from InspectTHIS__Applied_Questionnaire__c where id in: mapCSId.keyset()]; for(InspectTHIS__Applied_Questionnaire__c cs: lstdct){ cs.AttachmentId__c = mapCSId.get(cs.id); } if(!lstdct.isEmpty()){ update lstdct; } } }
May I request you please refer the below link for Test class for attachment.
- https://developer.salesforce.com/forums/?id=906F00000008yzKIAQ
- http://salesforce.stackexchange.com/questions/25838/test-class-for-sending-email-with-attachment
I hope it will be helpful.Best Regards
Rahul Kumar
Thanks for the suggestions, but I have looked through those examples previously. I am more struggling wiht the getkeyprefix() and the corresponding keyset.
Steve