function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hrishikesh KolheHrishikesh Kolhe 

List has no rows for assignment to SObject How to fix this error for Below Code

public class invoice {

public Salesorder__c so{get;set;}
public Invoice__c i{get;set;}
public list<Salesorder_Line_Product__c> soliList{get;set;}
   public list<Invoice_Line_Product_No__c> iliList{get;set;}
public string s{get;set;}

public invoice ()
{
s=apexpages.currentpage().getparameters().get('id');

so= new Salesorder__c();
i=new Invoice__c();

soliList= new list <Salesorder_Line_Product__c>();
  iliList= new list <Invoice_Line_Product_No__c>();

so=[SELECT id,Account_Management__c,Contact_Management__c,Delivery_Lead_Time__c,Opportunity_Management__c,Payment_terms__c,Quote__c,Remarks__c,Salesorder_Date__c,Warranty__c FROM Salesorder__c WHERE id=:s];

soliList=[SELECT id,Account_Name__c,Actual_price__c,Balanced_Quantity__c,CGST__c,CGST_Amount__c,Product__c,Discounted_Price__c,Discount_Type__c,Discount_Value__c,IGST__c,Quote_Name__c,Product_Description__c,Quantity__c,Salesorder_Name__c,SGST__c,SGST_Amount__c,Total_Price__c,Unit_price__c FROM Salesorder_Line_Product__c WHERE Salesorder_Name__c=:s];



i.Salesorder__c=so.id;
i.Account_Management__c=so.Account_Management__c;
i.Contact_Management__c= so.Contact_Management__c;
i.Delivery_Lead_Time__c=so.Delivery_Lead_Time__c;
i.Opportunity_Management__c=so.Opportunity_Management__c;
i.Payment_terms__c=so.Payment_terms__c;
i.Quote__c=so.Quote__c;
  // i.Remarks__c = so.Remarks__c;
i.Valid_Till__c=so.Valid_Till__c;
i.Warranty__c=so.Warranty__c;

for(Salesorder_Line_Product__c sol:soliList)
{


Salesorder_Line_Product__c inv= new Salesorder_Line_Product__c ();
inv.Salesorder_Name__c=sol.Salesorder_Name__c;
inv.Account_Name__c=sol.Account_Name__c;
inv.Actual_Price__c =sol.Actual_Price__c;
 inv.Quantity__c = sol.Balanced_Quantity__c;   
inv.CGST__c =sol.CGST__c;               
inv.Product__c = sol.Product__c; 
inv.Discount_Type__c=sol.Discount_Type__c;
inv.Discount_Value__c=sol.Discount_Value__c;
inv.IGST__c=sol.IGST__c;
inv.Opportunity_Name__c=sol.Opportunity_Name__c;
inv.Product_Description__c=sol.Product_Description__c;
inv.Quote_Name__c = sol.Quote_Name__c;
inv.SGST__c=sol.SGST__c;
inv.Unit_Price__c=sol.Unit_Price__c;

 // iliList.add(inv);
}

}

public pageReference saveit()
{
    insert i;
    
    for(Invoice_Line_Product_No__c inv: iliList)
    {
   //  inv.Invoice__c = i.Id;
    }
    
    insert iliList;
    
    pageReference pr = new pageReference('/'+s);
    return pr;
    
}

public pageReference cancelit()
{
    
    pageReference pr = new pageReference('/'+s);
    return pr;

}
}
Getting errors invoice is not visible showing this error list has no rows for assignment to SObject
Best Answer chosen by Hrishikesh Kolhe
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hrishikesh,

Some of the query in the above code is not returing result which is causing the issue. I hope you can find the exact line of the error in the debug logs.

Please find the below artcile for the same.

https://help.salesforce.com/s/articleView?id=000159853&language=en_US&r=https%3A%2F%2Fwww.google.com%2F&type=1 (https://help.salesforce.com/s/articleView?id=000159853&language=en_US&r=https%3A%2F%2Fwww.google.com%2F&type=1)

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hrishikesh,

Some of the query in the above code is not returing result which is causing the issue. I hope you can find the exact line of the error in the debug logs.

Please find the below artcile for the same.

https://help.salesforce.com/s/articleView?id=000159853&language=en_US&r=https%3A%2F%2Fwww.google.com%2F&type=1 (https://help.salesforce.com/s/articleView?id=000159853&language=en_US&r=https%3A%2F%2Fwww.google.com%2F&type=1)

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
Vivek   9Vivek 9
Can you share the link of the page with the parameters?