You need to sign in to do that
Don't have an account?

System.NullPointerException: Attempt to de-reference a null object Error
The line attempting to create the Set "ids" is throwing an error upon insert of a new lead.
Here is the error "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, leadTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object".
How do you get the Id for trigger.new?
Here is the error "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, leadTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object".
How do you get the Id for trigger.new?
trigger leadTrigger on Lead (before insert, after insert, after update) { Set<ID> ids = Trigger.newMap.keySet(); // getting error here List<Lead> triggerLeads = [SELECT Id, Email, LeadSource FROM Lead WHERE Id in :ids]; }
newMap is a map of IDs to the new versions of the sObject records and only available in before update, after insert, and after update triggers.
Remove before insert event and try again.
All Answers
You need to initalize your set. Try this
newMap is a map of IDs to the new versions of the sObject records and only available in before update, after insert, and after update triggers.
Remove before insert event and try again.