You need to sign in to do that
Don't have an account?
shakila G
Argument cannot be null in Apex class
Hi All,
When the Belowmethod called through VF page button , SOme time am getting below error
Argument cannot be null.
Error is in expression '{!addworkorders}' in component <apex:commandButton> in page check_available_rawmaterials: Class.Check_Available_Rawmaterials.addworkorders: line 40, column 1
Kindly please help me to over come from this issue
public void addworkorders() {
AttachmentCallWrapperlist3.clear();
setprodid.clear();
setRMid.clear();
lstrmri.clear();
lstComp .clear();
iRmInvLst.clear();
AttachmentCallWrapperlist.clear();
AttachmentCallWrapperlist3.clear();
Productnamemap.clear();
Productqtymap.clear();
show = true;
Boolean isTrue = TRUE;
IF(setprojectid!=Null){
lstrmri =[select ID,Product2Id,Quantity from OpportunityLineItem where OpportunityID=:setprojectid];
IF(lstrmri .size()>1){
For(OpportunityLineItem olt:lstrmri ){ setprodid.add(olt.Product2Id);
}
}
}
If(lstrmri.size()>0) { wraplist=new List<AddWrapperField1>();
Result=[select SUM(Quantity) Totalqty,Product2.name ProdName from OpportunityLineItem where opportunityID=:setprojectid group By Product2.name];
for(AggregateResult res:Result){ wraplist.add(new AddWrapperField1(Res));
Productqtymap.put((String)res.get('ProdName'), (Decimal)res.get('Totalqty'));
}
}
IF(setprodid!=Null){
lstComp =[select ID,name,Raw_Material__c,Selected__c,Product__R.name,Total_Measurement__c from Component__c where Product__r.name in : Productqtymap.keyset()];
If(lstComp .size()>0) {
wraplist1=new List<AddWrapperField>();
Result1=[select SUM(Total_Measurement__c) TotalMeasure,Raw_Material__r.name Name,Product__r.name pName from Component__c where Product__r.name in : Productqtymap.keyset()
group By Product__r.name,Raw_Material__r.name];
Result2=[select Raw_Material__r.name Name from Component__c where Product__r.name in : Productqtymap.keyset()
group By Raw_Material__r.name];
for(AggregateResult res1:Result1){
AttachmentCallWrapper I= New AttachmentCallWrapper();
i.qty=0;
if(Productqtymap!=null){
Rawmaterialmap.put((string)res1.get('Name'),(Double)res1.get('TotalMeasure')* Productqtymap.Get((String)res1.get('pName')));
}
i.RequiredMaterial =(string)res1.get('Name');
i.Qty=Rawmaterialmap.get((string)res1.get('Name'));
i.ProductName =(string)res1.get('pName');
i.ProdutQty = Productqtymap.Get((String)res1.get('pName'));
AttachmentCallWrapperlist.add(i);
}
For(AttachmentCallWrapper atc: AttachmentCallWrapperlist){
if (Productqtymap.containskey(atc.RequiredMaterial)){
Productqtymap.put(atc.RequiredMaterial, (atc.Qty+ Productqtymap.get(atc.RequiredMaterial)) );
Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);
}Else{
Productqtymap.put(atc.RequiredMaterial, atc.Qty);
Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);
}
}
}
}
iRmInvLst=[SELECT id,Name,RawMaterial__c,Available_RM_in_OrigMeasure__c ,Unit__c FROM Raw_Material_Inventory__c
WHERE Name IN :Productnamemap.keyset()];
IF(iRmInvLst.Size()>0){
For(Raw_Material_Inventory__c INV: iRmInvLst){
AttachmentCallWrapper2 atc4 = new AttachmentCallWrapper2();
atc4.RequiredMaterial=INV.NAME;
atc4.Stock=INV.Available_RM_in_OrigMeasure__c;
if(INV.Available_RM_in_OrigMeasure__c<Productqtymap.get(INV.NAME))
{
atc4.Requiredqty=Productqtymap.get(INV.NAME)-INV.Available_RM_in_OrigMeasure__c;
atc4.PurchaseUnit=INV.Unit__C;
}
atc4.Qty=Productqtymap.get(INV.NAME);
AttachmentCallWrapperlist3.add(atc4);
}
}
}
Thanks,
Shakila
When the Belowmethod called through VF page button , SOme time am getting below error
Argument cannot be null.
Error is in expression '{!addworkorders}' in component <apex:commandButton> in page check_available_rawmaterials: Class.Check_Available_Rawmaterials.addworkorders: line 40, column 1
Kindly please help me to over come from this issue
public void addworkorders() {
AttachmentCallWrapperlist3.clear();
setprodid.clear();
setRMid.clear();
lstrmri.clear();
lstComp .clear();
iRmInvLst.clear();
AttachmentCallWrapperlist.clear();
AttachmentCallWrapperlist3.clear();
Productnamemap.clear();
Productqtymap.clear();
show = true;
Boolean isTrue = TRUE;
IF(setprojectid!=Null){
lstrmri =[select ID,Product2Id,Quantity from OpportunityLineItem where OpportunityID=:setprojectid];
IF(lstrmri .size()>1){
For(OpportunityLineItem olt:lstrmri ){ setprodid.add(olt.Product2Id);
}
}
}
If(lstrmri.size()>0) { wraplist=new List<AddWrapperField1>();
Result=[select SUM(Quantity) Totalqty,Product2.name ProdName from OpportunityLineItem where opportunityID=:setprojectid group By Product2.name];
for(AggregateResult res:Result){ wraplist.add(new AddWrapperField1(Res));
Productqtymap.put((String)res.get('ProdName'), (Decimal)res.get('Totalqty'));
}
}
IF(setprodid!=Null){
lstComp =[select ID,name,Raw_Material__c,Selected__c,Product__R.name,Total_Measurement__c from Component__c where Product__r.name in : Productqtymap.keyset()];
If(lstComp .size()>0) {
wraplist1=new List<AddWrapperField>();
Result1=[select SUM(Total_Measurement__c) TotalMeasure,Raw_Material__r.name Name,Product__r.name pName from Component__c where Product__r.name in : Productqtymap.keyset()
group By Product__r.name,Raw_Material__r.name];
Result2=[select Raw_Material__r.name Name from Component__c where Product__r.name in : Productqtymap.keyset()
group By Raw_Material__r.name];
for(AggregateResult res1:Result1){
AttachmentCallWrapper I= New AttachmentCallWrapper();
i.qty=0;
if(Productqtymap!=null){
Rawmaterialmap.put((string)res1.get('Name'),(Double)res1.get('TotalMeasure')* Productqtymap.Get((String)res1.get('pName')));
}
i.RequiredMaterial =(string)res1.get('Name');
i.Qty=Rawmaterialmap.get((string)res1.get('Name'));
i.ProductName =(string)res1.get('pName');
i.ProdutQty = Productqtymap.Get((String)res1.get('pName'));
AttachmentCallWrapperlist.add(i);
}
For(AttachmentCallWrapper atc: AttachmentCallWrapperlist){
if (Productqtymap.containskey(atc.RequiredMaterial)){
Productqtymap.put(atc.RequiredMaterial, (atc.Qty+ Productqtymap.get(atc.RequiredMaterial)) );
Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);
}Else{
Productqtymap.put(atc.RequiredMaterial, atc.Qty);
Productnamemap.put(atc.RequiredMaterial,atc.RequiredMaterial);
}
}
}
}
iRmInvLst=[SELECT id,Name,RawMaterial__c,Available_RM_in_OrigMeasure__c ,Unit__c FROM Raw_Material_Inventory__c
WHERE Name IN :Productnamemap.keyset()];
IF(iRmInvLst.Size()>0){
For(Raw_Material_Inventory__c INV: iRmInvLst){
AttachmentCallWrapper2 atc4 = new AttachmentCallWrapper2();
atc4.RequiredMaterial=INV.NAME;
atc4.Stock=INV.Available_RM_in_OrigMeasure__c;
if(INV.Available_RM_in_OrigMeasure__c<Productqtymap.get(INV.NAME))
{
atc4.Requiredqty=Productqtymap.get(INV.NAME)-INV.Available_RM_in_OrigMeasure__c;
atc4.PurchaseUnit=INV.Unit__C;
}
atc4.Qty=Productqtymap.get(INV.NAME);
AttachmentCallWrapperlist3.add(atc4);
}
}
}
Thanks,
Shakila