You need to sign in to do that
Don't have an account?
Harry1008
Test class for the attachment on Lead apex trigger
HI all,
Could you please help me in writing a test class for the following apex trigger. The trigger is to change the lead status to Negotiation when the user attach the file on to the lead.
Thank you for your help.
Could you please help me in writing a test class for the following apex trigger. The trigger is to change the lead status to Negotiation when the user attach the file on to the lead.
Thank you for your help.
trigger UploadFileLead on Attachment (after insert, after update) { List <Lead> LeadList = new List<Lead>(); List <Lead> LeadListToUpdate = new List<Lead>(); Set <Id> LeadIds = new Set <Id>(); if(trigger.isInsert || trigger.isUpdate) { for (Attachment attach : trigger.New) { //Check if added attachment is related to Lead or not if(attach.ParentId.getSobjectType() == Lead.SobjectType){ if(string.valueOf(attach.Name).startswith('.xls')) LeadIds.add(attach.ParentId); } } } LeadList = [select id, status from Lead where id in : LeadIds]; for(Lead lead : LeadList){ lead.Status = 'Negotiation'; } update LeadList; }
I am getting an error when I run the above test class. This is the error Class.UploadFileLeadTest.testAttachmentsInsertUpdate: line 33, column 1
I have added the values Venue name and channel in my test class
Lead newLead = new Lead() ;
newLead.FirstName = 'Cole';
newLead.LastName = 'Swain';
newLead.Company = 'BlueWave';
newLead.Status = 'Open';
newLead.Venue_Name__c ='demo';
newLead.Channel__c ='demo';
//add other required fields
insert newLead;
The error is as per below.