You need to sign in to do that
Don't have an account?
Filipe Baradelli
Visualforce Error: Attempt to dereference a null object
I'm trying to send the products that are added in the Catalog Order to the list of products in Opportunity. I'm making the same commands of the Catalog with the Opportunity, but the error appears : "Visualforce Error: Attempt to dereference a null object".
This is the code that calls the error and is from Class Catalog Controller.
/*
* prepareCart()
* Additional constructor helper method for initializing Cart variables.
*/
public pageReference prepareCart() {
if(!Catalog_Order__c.sObjectType.getDescribe().isCreateable()) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'Insufficient access'));
return null;
}
productSet = new Set<String>();
myOrder = new Catalog_Order__c();
myOpp = new Opportunity();
myLineItems = new List<Catalog_Line_item__c>();
myOppLineItems = new List<OpportunityLineItem>();
/*
This query tries to eliminate the constant creation of more and more Orders
It grabs the last catalog modified by the current user with the status of Cart
*/
Catalog_Order__c[] orderQuery = [SELECT Items__c,Total_Cost__c,Account__c,Id,(SELECT Id,Product__c,Product_Short_Description__c,Product_Price__c,Product_Name__c,Quantity__c,VF_Image__c FROM Catalog_Line_Items__r) FROM Catalog_Order__c WHERE Status__c = 'Cart' AND CreatedById =:UserInfo.getUserId() ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT 1];
Opportunity[] oppQuery = [SELECT Id,(SELECT Id, Name FROM Produtos__r) FROM Opportunity WHERE CreatedById =:UserInfo.getUserId() ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT 1];
if( orderQuery.size() > 0 ) {
myOrder = orderQuery[0];
myOpp = oppQuery[0];
List<Catalog_Line_Item__c> cliList = myOrder.getSObjects('Catalog_Line_Items__r'); //Get all Line Items for Order
List<OpportunityLineItem> opplilist = myOpp.getSObjects('Produtos__r');
if (cliList == null || cliList.size() < 1) {
// No Line Items in related list so do nothing
} else {
// Line Items returned, so add them to product set
for(Catalog_Line_Item__c cli : cliList) {
productSet.add( cli.Product__c );
}
// opplilist.add(myOpp.getSObject('Produtos__r'));
for(OpportunityLineItem oppli : opplilist){
productSet.add( oppli.ProductCode);
}
}
}
return null;
}
Can some one help me?
This is the code that calls the error and is from Class Catalog Controller.
/*
* prepareCart()
* Additional constructor helper method for initializing Cart variables.
*/
public pageReference prepareCart() {
if(!Catalog_Order__c.sObjectType.getDescribe().isCreateable()) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'Insufficient access'));
return null;
}
productSet = new Set<String>();
myOrder = new Catalog_Order__c();
myOpp = new Opportunity();
myLineItems = new List<Catalog_Line_item__c>();
myOppLineItems = new List<OpportunityLineItem>();
/*
This query tries to eliminate the constant creation of more and more Orders
It grabs the last catalog modified by the current user with the status of Cart
*/
Catalog_Order__c[] orderQuery = [SELECT Items__c,Total_Cost__c,Account__c,Id,(SELECT Id,Product__c,Product_Short_Description__c,Product_Price__c,Product_Name__c,Quantity__c,VF_Image__c FROM Catalog_Line_Items__r) FROM Catalog_Order__c WHERE Status__c = 'Cart' AND CreatedById =:UserInfo.getUserId() ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT 1];
Opportunity[] oppQuery = [SELECT Id,(SELECT Id, Name FROM Produtos__r) FROM Opportunity WHERE CreatedById =:UserInfo.getUserId() ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT 1];
if( orderQuery.size() > 0 ) {
myOrder = orderQuery[0];
myOpp = oppQuery[0];
List<Catalog_Line_Item__c> cliList = myOrder.getSObjects('Catalog_Line_Items__r'); //Get all Line Items for Order
List<OpportunityLineItem> opplilist = myOpp.getSObjects('Produtos__r');
if (cliList == null || cliList.size() < 1) {
// No Line Items in related list so do nothing
} else {
// Line Items returned, so add them to product set
for(Catalog_Line_Item__c cli : cliList) {
productSet.add( cli.Product__c );
}
// opplilist.add(myOpp.getSObject('Produtos__r'));
for(OpportunityLineItem oppli : opplilist){
productSet.add( oppli.ProductCode);
}
}
}
return null;
}
Can some one help me?
caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Class.Catalog_Controller.updateAccount: line 300, column 1
The code of this part is this :
/*
* updateAccount(String ID)
* Updates the Account field of the Order with the given Id
*/
public PageReference updateAccount() {
if(!Catalog_Order__c.sObjectType.getDescribe().isUpdateable()) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'Insufficient access'));
return null;
}
myOrder.Account__c = accountId;
update myOrder; // LINE 300
// Stay on current page
return null;
}
If I don't activate the Process Builder, the Opportunity is not created.
Just check for '===myorder====' in your debug log and see what comes.