You need to sign in to do that
Don't have an account?
amit wagaskar
how to write a test class for below apex trigger
//apex trigger
trigger Validate_attachment on Lead (before insert,before update) {
set<id> ldList=new set<id>();
list<lead>validatelead=[select id,name,leadsource,email from lead where id in:trigger.new];
for(lead newlead:trigger.new)
{
List<sObject> objList = new List<sObject>();
List<lead> leadList=[select id,FirstName,LastName,LeadSource,Email,Email_Sent__c from lead where id IN:trigger.new];
if((newlead.LeadSource=='Job Application India' || newlead.LeadSource=='Job Application Non-India')&& newlead.attachments.isempty())
{
system.debug('******');
newlead.adderror('please upload the attchament');
ldList.add(newlead.id);
}
}
//list <lead> validatelead = new list<lead>();
validatelead=[select id,name,leadsource,email,(select id,name from attachments) from lead where id in:ldList];
for(lead l:validatelead)
{
if(l.attachments.size()==null)
{
l.adderror('please upload the attchament');
}
}
}
trigger Validate_attachment on Lead (before insert,before update) {
set<id> ldList=new set<id>();
list<lead>validatelead=[select id,name,leadsource,email from lead where id in:trigger.new];
for(lead newlead:trigger.new)
{
List<sObject> objList = new List<sObject>();
List<lead> leadList=[select id,FirstName,LastName,LeadSource,Email,Email_Sent__c from lead where id IN:trigger.new];
if((newlead.LeadSource=='Job Application India' || newlead.LeadSource=='Job Application Non-India')&& newlead.attachments.isempty())
{
system.debug('******');
newlead.adderror('please upload the attchament');
ldList.add(newlead.id);
}
}
//list <lead> validatelead = new list<lead>();
validatelead=[select id,name,leadsource,email,(select id,name from attachments) from lead where id in:ldList];
for(lead l:validatelead)
{
if(l.attachments.size()==null)
{
l.adderror('please upload the attchament');
}
}
}
All Answers
yes you are right ,i posted wrong code.
the right code should be like:
trigger Validate_attachment on Lead (before insert,before update) {
set<id> ldList=new set<id>();
list<lead>validatelead=[select id,name,leadsource,email from lead where id in:trigger.new];
for(lead newlead:trigger.new)
{
//List<sObject> objList = new List<sObject>();
//List<lead> leadList=[select id,FirstName,LastName,LeadSource,Email,Email_Sent__c from lead where id IN:trigger.new];
if((newlead.LeadSource=='Job Application India' || newlead.LeadSource=='Job Application Non-India')&& newlead.attachments.isempty())
{
system.debug('******');
newlead.adderror('please upload the attchament');
// ldList.add(newlead.id);
}
}
}