You need to sign in to do that
Don't have an account?
Lisa Schutter
Error with Lead converstion
Hi everyone, I hope someone can give me a sollution. It is not possible for our users to convert a lead without an opportunity. I will copy the errors below and the Apex Class LeadUtil. Also I will so the place where I think the Apex Code is not corrert.
This is the error in the debug log:
11:18:09.125 (1125730322)|METHOD_EXIT|[2]|01pw0000003wWyK|LeadUtil.entry(LeadUtil.TriggerParams) 11:18:09.125 (1125865020)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Class.LeadUtil.entry: line 104, column 1 Trigger.LeadTrigger: line 2, column 1 11:18:09.125 (1125880838)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
This is error on the User interface:
Error: System.DmlException: Update failed. First exception on row 0 with id 00Qw000000nUFTUEA4; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadTrigger: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Class.LeadUtil.entry: line 104, column 1 Trigger.LeadTrigger: line 2, column 1: [] (System Code)
I think this is place in code which has to be changed:
//l.ConvertedOpportunityId, l.ConvertedContactId
if(rt.DeveloperName == 'PersonAccount'){
Opportunity opp = (l.ConvertedOpportunityId != null) ? new Opportunity(id=l.ConvertedOpportunityId): null;
This is the full Apex LeadUtil:
public class LeadUtil {
//ab
//Contains all trigger information
public class TriggerParams {
public Boolean isBefore;
public Boolean isAfter;
public Boolean isInsert;
public Boolean isUpdate;
public Boolean isDelete;
public Boolean isUndelete;
public List<sObject> triggerNew;
public List<sObject> triggerOld;
public Map<Id, sObject> newMap;
public Map<Id, sObject> oldMap;
public TriggerParams(Boolean isBefore, Boolean isAfter, Boolean isInsert, Boolean isUpdate,
Boolean isDelete, Boolean isUndelete, List<sObject> triggerNew,
List<sObject> triggerOld, Map<Id, sObject> newMap, Map<Id, sObject> oldMap) {
this.isBefore = isBefore;
this.isAfter = isAfter;
this.isInsert = isInsert;
this.isUpdate = isUpdate;
this.isDelete = isDelete;
this.isUndelete = isUndelete;
this.triggerNew = triggerNew;
this.triggerOld = triggerOld;
this.newMap = newMap;
this.oldMap = oldMap;
}
}
//here all methods should be called
public static void entry(TriggerParams triggerParams) {
List<Lead> triggerNew = (List<Lead>)triggerParams.triggerNew;
String userType = userinfo.getUserType();
if(triggerParams.isBefore){
if(triggerParams.isInsert){
if(userType == 'PowerPartner'){ //ab - more info on http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_user.htm
Id userId = userinfo.getUserId();
User u = [Select Id, Contact.AccountId from User where Id=:userId];
Id partnerAccount = u.Contact.AccountId;
for(Lead l : triggerNew){
l.Leadsource__c = partnerAccount;
l.LeadSource = 'LeaseCo';
}
}
}
if(triggerParams.isUpdate){
for(Lead l : triggerNew) {
if (l.IsConverted){
system.debug('############## Acc Id -->' + l.ConvertedAccountId);
Account acc = [select Id, RecordTypeId, PersonContactId from Account where Id = :l.ConvertedAccountId];
system.debug('############## Acc RecordTypeId : ' + acc.RecordTypeId);
RecordType rt = [Select DeveloperName From RecordType where Id = :acc.RecordTypeId];
system.debug('############## RecordType Name : ' + rt.DeveloperName);
//l.ConvertedOpportunityId, l.ConvertedContactId
if(rt.DeveloperName == 'PersonAccount'){
Opportunity opp = (l.ConvertedOpportunityId != null) ? new Opportunity(id=l.ConvertedOpportunityId): null;
acc.Account_manager__c = l.Account_Manager__c;
acc.Car_Delivery_Date__pc = l.Car_Delivery_Date__c;
acc.Brand_Car__c = l.Brand_Car__c;
acc.Car_type__c = l.Type_Car__c;
acc.Phone = l.Company_Phone__c;
acc.AccountSource = l.LeadSource;
acc.just_converted__c = false;
update acc;
Contact con = (l.ConvertedContactId != null) ? new Contact(id=l.ConvertedContactId): null;
con.HomePhone = l.Phone;
con.MobilePhone = l.MobilePhone;
update con;
opp.Send_Quote_To__c = (l.Account_Manager__c != null) ? l.Account_Manager__c : Acc.PersonContactId;
opp.Leadsource__c = l.Leadsource__c;
opp.LeadSource = l.LeadSource;
update opp;
}
else if(rt.DeveloperName == 'Business_Account'){
Opportunity opp = (l.ConvertedOpportunityId != null) ? new Opportunity(id=l.ConvertedOpportunityId): null;
Contact con = (l.ConvertedContactId != null) ? new Contact(id=l.ConvertedContactId): null;
acc.Phone = l.Company_Phone__c;
acc.Account_manager__c = l.Account_Manager__c;
acc.Leadsource__c = l.Leadsource__c;
acc.AccountSource = l.LeadSource;
acc.ParentId = l.Parent_Account__c;
acc.ShippingStreet = l.street;
acc.ShippingCity = l.City;
acc.ShippingState = l.State;
acc.ShippingCountry = l.Country;
acc.ShippingPostalcode = l.PostalCode;
acc.just_converted__c = false;
update acc;
opp.Send_Quote_To__c = (l.Account_Manager__c != null) ? l.Account_Manager__c : null;
opp.Leadsource__c = l.Leadsource__c;
opp.LeadSource = l.LeadSource;
update opp;
con.Phone = l.Phone;
update con;
}
else if(rt.DeveloperName == 'Partner_Account'){
}
}
}
}
}
}
}
Thanks in advance!
This is the error in the debug log:
11:18:09.125 (1125730322)|METHOD_EXIT|[2]|01pw0000003wWyK|LeadUtil.entry(LeadUtil.TriggerParams) 11:18:09.125 (1125865020)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Class.LeadUtil.entry: line 104, column 1 Trigger.LeadTrigger: line 2, column 1 11:18:09.125 (1125880838)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
This is error on the User interface:
Error: System.DmlException: Update failed. First exception on row 0 with id 00Qw000000nUFTUEA4; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadTrigger: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Class.LeadUtil.entry: line 104, column 1 Trigger.LeadTrigger: line 2, column 1: [] (System Code)
I think this is place in code which has to be changed:
//l.ConvertedOpportunityId, l.ConvertedContactId
if(rt.DeveloperName == 'PersonAccount'){
Opportunity opp = (l.ConvertedOpportunityId != null) ? new Opportunity(id=l.ConvertedOpportunityId): null;
This is the full Apex LeadUtil:
public class LeadUtil {
//ab
//Contains all trigger information
public class TriggerParams {
public Boolean isBefore;
public Boolean isAfter;
public Boolean isInsert;
public Boolean isUpdate;
public Boolean isDelete;
public Boolean isUndelete;
public List<sObject> triggerNew;
public List<sObject> triggerOld;
public Map<Id, sObject> newMap;
public Map<Id, sObject> oldMap;
public TriggerParams(Boolean isBefore, Boolean isAfter, Boolean isInsert, Boolean isUpdate,
Boolean isDelete, Boolean isUndelete, List<sObject> triggerNew,
List<sObject> triggerOld, Map<Id, sObject> newMap, Map<Id, sObject> oldMap) {
this.isBefore = isBefore;
this.isAfter = isAfter;
this.isInsert = isInsert;
this.isUpdate = isUpdate;
this.isDelete = isDelete;
this.isUndelete = isUndelete;
this.triggerNew = triggerNew;
this.triggerOld = triggerOld;
this.newMap = newMap;
this.oldMap = oldMap;
}
}
//here all methods should be called
public static void entry(TriggerParams triggerParams) {
List<Lead> triggerNew = (List<Lead>)triggerParams.triggerNew;
String userType = userinfo.getUserType();
if(triggerParams.isBefore){
if(triggerParams.isInsert){
if(userType == 'PowerPartner'){ //ab - more info on http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_user.htm
Id userId = userinfo.getUserId();
User u = [Select Id, Contact.AccountId from User where Id=:userId];
Id partnerAccount = u.Contact.AccountId;
for(Lead l : triggerNew){
l.Leadsource__c = partnerAccount;
l.LeadSource = 'LeaseCo';
}
}
}
if(triggerParams.isUpdate){
for(Lead l : triggerNew) {
if (l.IsConverted){
system.debug('############## Acc Id -->' + l.ConvertedAccountId);
Account acc = [select Id, RecordTypeId, PersonContactId from Account where Id = :l.ConvertedAccountId];
system.debug('############## Acc RecordTypeId : ' + acc.RecordTypeId);
RecordType rt = [Select DeveloperName From RecordType where Id = :acc.RecordTypeId];
system.debug('############## RecordType Name : ' + rt.DeveloperName);
//l.ConvertedOpportunityId, l.ConvertedContactId
if(rt.DeveloperName == 'PersonAccount'){
Opportunity opp = (l.ConvertedOpportunityId != null) ? new Opportunity(id=l.ConvertedOpportunityId): null;
acc.Account_manager__c = l.Account_Manager__c;
acc.Car_Delivery_Date__pc = l.Car_Delivery_Date__c;
acc.Brand_Car__c = l.Brand_Car__c;
acc.Car_type__c = l.Type_Car__c;
acc.Phone = l.Company_Phone__c;
acc.AccountSource = l.LeadSource;
acc.just_converted__c = false;
update acc;
Contact con = (l.ConvertedContactId != null) ? new Contact(id=l.ConvertedContactId): null;
con.HomePhone = l.Phone;
con.MobilePhone = l.MobilePhone;
update con;
opp.Send_Quote_To__c = (l.Account_Manager__c != null) ? l.Account_Manager__c : Acc.PersonContactId;
opp.Leadsource__c = l.Leadsource__c;
opp.LeadSource = l.LeadSource;
update opp;
}
else if(rt.DeveloperName == 'Business_Account'){
Opportunity opp = (l.ConvertedOpportunityId != null) ? new Opportunity(id=l.ConvertedOpportunityId): null;
Contact con = (l.ConvertedContactId != null) ? new Contact(id=l.ConvertedContactId): null;
acc.Phone = l.Company_Phone__c;
acc.Account_manager__c = l.Account_Manager__c;
acc.Leadsource__c = l.Leadsource__c;
acc.AccountSource = l.LeadSource;
acc.ParentId = l.Parent_Account__c;
acc.ShippingStreet = l.street;
acc.ShippingCity = l.City;
acc.ShippingState = l.State;
acc.ShippingCountry = l.Country;
acc.ShippingPostalcode = l.PostalCode;
acc.just_converted__c = false;
update acc;
opp.Send_Quote_To__c = (l.Account_Manager__c != null) ? l.Account_Manager__c : null;
opp.Leadsource__c = l.Leadsource__c;
opp.LeadSource = l.LeadSource;
update opp;
con.Phone = l.Phone;
update con;
}
else if(rt.DeveloperName == 'Partner_Account'){
}
}
}
}
}
}
}
Thanks in advance!
Below link contains almost a similar issue.
http://salesforce.stackexchange.com/questions/72527/converting-lead-into-account-trigger-before-insert-before-update
Please let me know if this helps
Best Regards
Naga Kiran