You need to sign in to do that
Don't have an account?
SId.New dev
Trigger error
trigger TriggerOnLead on Lead (before insert) { Map<String, Lead> mapLead1 = new Map<String, Lead>(); SYSTEM.DEBUG('!!!!!!!!!!mapLead1!!!!!!!!!!!'+mapLead1); Map<String, Lead> mapLead2 = new Map<String, Lead>(); SYSTEM.DEBUG('+++++++++++mapLead2 +++++++++++++++'+mapLead2 ); for (Lead lead : System.Trigger.new) { mapLead1.put(lead.concatinate_name_and_email__c.TOLOWERCASE().TRIM(), lead); mapLead2.put(lead.concatinate_name_and_phone__c.TOLOWERCASE().TRIM(), lead); } list<lead> lead1=[SELECT Id,Name,Email,Phone,concatinate_name_and_email__c FROM Lead WHERE concatinate_name_and_email__c IN :mapLead1.KeySet()]; list<lead> lead2=[SELECT Id,Name,Email,Phone,concatinate_name_and_phone__c FROM Lead WHERE concatinate_name_and_phone__c IN :mapLead2.KeySet()]; for (Lead lead4 : System.Trigger.new) { if(lead4.Any_way_save_record__c!=true) { if(lead1.size()>0) /*at this line error is coming. */ { for (Lead lead :lead1){ Lead newLead = mapLead1.get(lead.concatinate_name_and_email__c.TOLOWERCASE().TRIM()); SYSTEM.DEBUG('*************mapLead1************************'+mapLead1); SYSTEM.DEBUG('@@@@@@@@@newLead@@@@@@@@@@@@@@@'+newLead); newLead.addError('already exists<a style=color:GREEN href=/apex/leaderror?id='+LEAD.ID+'>'+ lead.name + '</a>'); }}else if(lead2.size()>0){ for (Lead lead :lead2 ) { Lead newLead1 = mapLead2.get(lead.concatinate_name_and_phone__c.TOLOWERCASE().TRIM()); SYSTEM.DEBUG('%%%%%%%%%%%%newLead1%%%%%%%%%%%%%%%%%%'+newLead1); newLead1.addError('already existse<a style=color:GREEN href=/apex/leaderror?id='+LEAD.ID+'>'+ lead.name + '</a>'); } } } } }
TR: Sandbox: Developer script exception : TriggerOnLead : TriggerOnLead: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TriggerOnLead: line 22, column 1
It is blowing up on your lead.concatinate_name_and_email__c field being nul:
Try this instead:
if (lead.concatinate_name_and_email__c != null) {
Lead newLead = mapLead1.get(lead.concatinate_name_and_email__c.TOLOWERCASE().TRIM());
SYSTEM.DEBUG('*************mapLead1************************'+mapLead1);
SYSTEM.DEBUG('@@@@@@@@@newLead@@@@@@@@@@@@@@@'+newLead);
newLead.addError('already exists<a style=color:GREEN href=/apex/leaderror?id='+LEAD.ID+'>'+ lead.name + '</a>');
}
Best,
Ram
All Answers
It is blowing up on your lead.concatinate_name_and_email__c field being nul:
Try this instead:
if (lead.concatinate_name_and_email__c != null) {
Lead newLead = mapLead1.get(lead.concatinate_name_and_email__c.TOLOWERCASE().TRIM());
SYSTEM.DEBUG('*************mapLead1************************'+mapLead1);
SYSTEM.DEBUG('@@@@@@@@@newLead@@@@@@@@@@@@@@@'+newLead);
newLead.addError('already exists<a style=color:GREEN href=/apex/leaderror?id='+LEAD.ID+'>'+ lead.name + '</a>');
}
Best,
Ram
Hi. Thanks for your reply. Had you worked on Contact share.please see why it is not working
in sufficient previlages error is coming.please try to solve this,
for detail:--
http://boards.developerforce.com/t5/Apex-Code-Development/ContactShare-using-apex/td-p/611543
Can you post the line on which you get the permissions error? Are you running this as a standard user or sys admin?
Ram