0

I am making a lightning component for a user to create a quote + line items quick and easy. However the apex function that is meant to query the pricebook entry and its Id for each line item is causing an internal salesforce error.

I am unsure as to why, because another function has pretty much the same query and works fine.

Here is the function currently breaking:

@AuraEnabled
public static String createQuoteAndLineItems(Quote newQuote, List<QuoteLineItem> newQuoteItems)
{
    try
    {
        //insert newQuote;
        for(QuoteLineItem currentItem : newQuoteItems)
        {
            currentItem.QuoteId = newQuote.Id;
            system.debug(currentItem);
            system.debug(currentItem.UnitPrice);
            system.debug(currentItem.Collection_Frequency__c);
            system.debug(currentItem.QuoteId);
            system.debug(currentItem.Product2Id);
        }
        //insert newQuoteItems;
        return 'Success';
    }
    catch(exception e)
    {
        system.debug(e.getMessage() + ' ' + e.getStackTraceString());
        return e.getMessage() + '\n' + e.getStackTraceString();
    }
}

Internal error caused when trying to debug or query using Product2Id.

Update: Turns out I needed to do "Product2Id.Id" instead of just "Product2Id"... lol

8
  • can your print and see size of newQuoteItems ? Jun 10, 2019 at 9:14
  • Yeah, I can see them in my debug. However something new i've discovered is when I try to just debug the product2Id, it also gives an internal error. But the list I debug shows the product2Id just fine Jun 10, 2019 at 9:15
  • You are doing SOQL in for-loop hich will cause Limits Exception which cannot be caught by the catch block and you are getting Internal Salesforce Errr. Jun 10, 2019 at 9:16
  • Ah alright. I normally avoid soql in for loops, but I couldn't figure a way around this one. At most 10 queries are done so I thought it'd be alright, guess not ahah Jun 10, 2019 at 9:18
  • Hi, so I've removed any queries done, and just have debugs. If I try to debug any specific field on the quotelineitem from the list i've passed in, I get an internal error. Debugging the whole item works fine though? Jun 10, 2019 at 9:33

1 Answer 1

0

I figured out why it's breaking. The custom lookup I was using for Product2Id had Product2Id as an object holding the name and the Id of the selected record.

So I just needed to pass in only the Id in my JS controller with Product2Id.Id.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .