You need to sign in to do that
Don't have an account?
Balasubramani Dhanapal
Apex class
Hi all,
I am begginer in salesforce.I have added below code in apex class.
"Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Attempt to de-reference a null object: []"
This type of error.Please help me anyone.
Apex class:
AddPSProducts(newOppMap);
Private void AddPSProducts(Map<Id,Opportunity> newOppMap){
List<Opportunity> listOppsToAddProduct=new list<Opportunity>();
List<id> listAccIds=new List<Id>();
List<id> listPSIds=new List<Id>();
for(Opportunity opp:newOppMap.values()){ //Collecting the Accounts ids from the Triggered Opportunities
if(opp.Project_Sheet__c!= NULL){
listPSIds.add(opp.Project_Sheet__c);
listAccIds.add(opp.AccountId);
}
}
//To avoid Unneccessary Executions.
if(listPSIds.size() == 0) return;
Map<Id,Account> customerMap=new Map<Id,Account>([select id,Delivery_Charged_for__c,Price_Book_ID__c from Account where id IN: listAccIds]);
Map<Id,Project_Sheet__c> psMap=new Map<Id,Project_Sheet__c>([SELECT id,Visit__r.Products__c,Site_Contract__c,Arrive__c,Depart__c,Visit__r.Quotation_Reference__c
FROM Project_Sheet__c
WHERE Id IN: listPSIds]);
for(Opportunity newOpp:newOppMap.values()){
if(psMap.containskey(newOpp.Project_Sheet__c) ){
listOppsToAddProduct.add(newOpp);
}
}
try{
if(listOppsToAddProduct.size()>0){
//Add Project Sheet Sheet Product to Opportunity
addProduct=new OpportuntiyAutoProducts(psMap);
System.debug('scMap========??'+scMap);
listOLIs.addAll(addProduct.AddPSVisitProducts(customerMap,listOppsToAddProduct,prodMap,producsPBEMap,scMap));
}
}Catch(Exception e){
String msg=e.getMessage();
for(Opportunity o:newOppMap.values()){
o.addError(msg);
}
}
}
Advance in Thanks
I am begginer in salesforce.I have added below code in apex class.
"Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Attempt to de-reference a null object: []"
This type of error.Please help me anyone.
Apex class:
AddPSProducts(newOppMap);
Private void AddPSProducts(Map<Id,Opportunity> newOppMap){
List<Opportunity> listOppsToAddProduct=new list<Opportunity>();
List<id> listAccIds=new List<Id>();
List<id> listPSIds=new List<Id>();
for(Opportunity opp:newOppMap.values()){ //Collecting the Accounts ids from the Triggered Opportunities
if(opp.Project_Sheet__c!= NULL){
listPSIds.add(opp.Project_Sheet__c);
listAccIds.add(opp.AccountId);
}
}
//To avoid Unneccessary Executions.
if(listPSIds.size() == 0) return;
Map<Id,Account> customerMap=new Map<Id,Account>([select id,Delivery_Charged_for__c,Price_Book_ID__c from Account where id IN: listAccIds]);
Map<Id,Project_Sheet__c> psMap=new Map<Id,Project_Sheet__c>([SELECT id,Visit__r.Products__c,Site_Contract__c,Arrive__c,Depart__c,Visit__r.Quotation_Reference__c
FROM Project_Sheet__c
WHERE Id IN: listPSIds]);
for(Opportunity newOpp:newOppMap.values()){
if(psMap.containskey(newOpp.Project_Sheet__c) ){
listOppsToAddProduct.add(newOpp);
}
}
try{
if(listOppsToAddProduct.size()>0){
//Add Project Sheet Sheet Product to Opportunity
addProduct=new OpportuntiyAutoProducts(psMap);
System.debug('scMap========??'+scMap);
listOLIs.addAll(addProduct.AddPSVisitProducts(customerMap,listOppsToAddProduct,prodMap,producsPBEMap,scMap));
}
}Catch(Exception e){
String msg=e.getMessage();
for(Opportunity o:newOppMap.values()){
o.addError(msg);
}
}
}
Advance in Thanks
BHinners
The error appears to be related to an insert operation, but I'm not seeing an insert operation in your code. Also, these errors generally give you specifics about what is null, and it looks like it should be the validation field, but I don't see that in your code either. Is there something missing, or am I reading it wrong?