You need to sign in to do that
Don't have an account?
getting error in test class for Attachment Email Apex class
- @isTest
- private class OpportunityMatchingHelperTest {
- private static testMethod void testCreateRecord() {
- Id conRecID = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Student').getRecordTypeId();
- Id oppRecID = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Opportunity').getRecordTypeId();
- Test.startTest();
- Account acc = new Account(Name = 'test');
- Insert acc;
- Contact con = new Contact(Lastname = 'test con',Email = 'test@gmail.com',AccountId = acc.Id,Academic_Standing__c = 'Good Standing',recordTypeId = conRecID);
- Insert con;
- Opportunity opp = new Opportunity(AccountId = acc.Id,recordTypeId = oppRecID,Name = 'Demo',StageName = 'Demo',CloseDate = System.Today(),Key_Contact__c = con.Id);
- Insert opp;
- alu_Opportunity_Matching__c aluOpp = new alu_Opportunity_Matching__c(Opportunity__c = opp.Id,Applicant_Student_Record__c = con.Id, Application_Status__c = 'Potential Candidate');
- Insert aluOpp;
- Blob b = Blob.valueOf('Test Data');
- Attachment attachment = new Attachment(ParentId = opp.id,Name = 'Test Attachment for Parent',Body = b);
- Insert attachment;
- aluOpp.Application_Status__c = 'Pitched';
- Update aluOpp;
- Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
- efa.setFileName( attachment.Name);
- efa.setBody(b);
- List<Attachment> attList = new List<Attachment>();
- for(Integer i=0;i<6;i++){
- Attachment Attac =new Attachment();
- Attac.Name='Unit Test Attachment';
- Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
- Attac.body=bodyBlob;
- Attac.parentId=opp.id;
- attList.add(Attac);
- }
- insert attList;
- }
- }