You need to sign in to do that
Don't have an account?
shakila G
Apex class : Argument Cannot be Null?
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 49, column 1
Which is Highlightes as Bold in the below mentioned code
Kindly please help me to over come from this issue
public void addworkorders() {
AttachmentCallWrapperlist3.clear();
setprodid.clear();
setRMid.clear();
lstrmri.clear();
lstComp .clear();
//wraplist.clear();
//Result.clear();
//Result1.clear();
//Result2.clear();
iRmInvLst.clear();
AttachmentCallWrapperlist.clear();
AttachmentCallWrapperlist3.clear();
Productnamemap.clear();
Productqtymap.clear();
show = true;
/*for (Project__c iRow:lstworkorder) {if (iRow.Selected__c == true) { setRMid.add(iRow.Opportunity__c);
}
} */
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];
IF(Result.size()>0){
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];
IF( Result1.SIZE()>0 && Productqtymap!=Null){
for(AggregateResult res2:Result1){
Rawmaterialmap.put((string)res2.get('Name'),(Double)res2.get('TotalMeasure')* Productqtymap.Get((String)res2.get('pName')));
}
}
If(Result1.size()>0 && Productqtymap!=NUll && Rawmaterialmap!=Null ){
for(AggregateResult res1:Result1){
AttachmentCallWrapper I= New AttachmentCallWrapper();
i.qty=0;
i.RequiredMaterial =(string)res1.get('Name');
If(Rawmaterialmap.size()>0){
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);
}
}
if(AttachmentCallWrapperlist.size()>0 && Productqtymap!=Null){
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 && Productqtymap!=Null){
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
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 49, column 1
Which is Highlightes as Bold in the below mentioned code
Kindly please help me to over come from this issue
public void addworkorders() {
AttachmentCallWrapperlist3.clear();
setprodid.clear();
setRMid.clear();
lstrmri.clear();
lstComp .clear();
//wraplist.clear();
//Result.clear();
//Result1.clear();
//Result2.clear();
iRmInvLst.clear();
AttachmentCallWrapperlist.clear();
AttachmentCallWrapperlist3.clear();
Productnamemap.clear();
Productqtymap.clear();
show = true;
/*for (Project__c iRow:lstworkorder) {if (iRow.Selected__c == true) { setRMid.add(iRow.Opportunity__c);
}
} */
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];
IF(Result.size()>0){
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];
IF( Result1.SIZE()>0 && Productqtymap!=Null){
for(AggregateResult res2:Result1){
Rawmaterialmap.put((string)res2.get('Name'),(Double)res2.get('TotalMeasure')* Productqtymap.Get((String)res2.get('pName')));
}
}
If(Result1.size()>0 && Productqtymap!=NUll && Rawmaterialmap!=Null ){
for(AggregateResult res1:Result1){
AttachmentCallWrapper I= New AttachmentCallWrapper();
i.qty=0;
i.RequiredMaterial =(string)res1.get('Name');
If(Rawmaterialmap.size()>0){
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);
}
}
if(AttachmentCallWrapperlist.size()>0 && Productqtymap!=Null){
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 && Productqtymap!=Null){
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
Please refer the below code
public void addworkorders() {
AttachmentCallWrapperlist3.clear();
setprodid.clear();
setRMid.clear();
lstrmri.clear();
lstComp .clear();
//wraplist.clear();
//Result.clear();
//Result1.clear();
//Result2.clear();
iRmInvLst.clear();
AttachmentCallWrapperlist.clear();
AttachmentCallWrapperlist3.clear();
Productnamemap.clear();
Productqtymap.clear();
show = true;
/*for (Project__c iRow:lstworkorder) {if (iRow.Selected__c == true) { setRMid.add(iRow.Opportunity__c);
}
} */
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];
IF(Result.size()>0){
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];
IF( Result1.SIZE()>0 && Productqtymap!=Null){
for(AggregateResult res2:Result1){
Rawmaterialmap.put((string)res2.get('Name'),(Double)res2.get('TotalMeasure')* Productqtymap.Get((String)res2.get('pName')));
}
}
If(Result1.size()>0 && Productqtymap!=NUll && Rawmaterialmap!=Null ){
for(AggregateResult res1:Result1){
AttachmentCallWrapper I= New AttachmentCallWrapper();
i.qty=0;
i.RequiredMaterial =(string)res1.get('Name');
If(Rawmaterialmap.size()>0){
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);
}
}
if(AttachmentCallWrapperlist.size()>0 && Productqtymap!=Null){
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 && Productqtymap!=Null){
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);
}
}
}