0

I'm doing a sync with OpportunityLineItem and QuoteLineItem based on this tutorial: http://rajgulshan.blogspot.com/2017/05/sync-quote-line-item-custom-fields-with.html

I've got a problem here:

private static Map<ID,ID> returnDefaultLinking(Set<ID> poIds)
{
    System.debug('++++++poIds ====>' + poIds);
    Map<ID,ID> mapSortOrder= new Map<ID,ID>();
    //String query='select id, name,(select id, Opportunity_Line_Item_ID__c from QuoteLineItems  ) from Quote where id in :poIds';
    //List<Quote> lstQuotesWithLineItems=Database.query(query);

    List<Quote> lstQuotesWithLineItems = new List<Quote>();
    lstQuotesWithLineItems = ([select id, name,(select id, Opportunity_Line_Item_ID__c from QuoteLineItems  ) 
                               from Quote where id in :poIds]);
    if(lstQuotesWithLineItems.size() > 0){
        for(Quote q : lstQuotesWithLineItems)
        {                
            if(q.QuoteLineItems !=null)
            {
                for(QuoteLineitem qli : q.QuoteLineItems)
                {
                    if(qli.Opportunity_Line_Item_ID__c!=null)
                    {
                        //map quote line item id with respective opportunity line item id
                         mapSortOrder.put(qli.Id,ID.valueOF(qli.Opportunity_Line_Item_ID__c));
                    } 
                }
            }
        }
    }
    return mapSortOrder;
}

Illegal assignment from List<Quote> to List<Quote>

Variable does not exist: QuoteLineItems

How can I resolve these problems?

2

1 Answer 1

1

I suspect you have a class or variable named Quote. For this reason, I always recommend you don't name classes or variables that are literally the same as a standard object. However, for now, you can fix that by prefixing it with Schema. You also have a number of unnecessary if statements; I've cleaned up those in this answer as well.


private static Map<ID,ID> returnDefaultLinking(Set<ID> poIds) {
    Map<ID,ID> mapSortOrder= new Map<ID,ID>();
    List<Schema.Quote> lstQuotesWithLineItems = [select id, name,(select id, Opportunity_Line_Item_ID__c from QuoteLineItems WHERE Opportunity_Line_Item_Id__c <> NULL) 
                               from Quote where id in :poIds];
    for(Schema.Quote q : lstQuotesWithLineItems) {
        for(QuoteLineitem qli : q.QuoteLineItems) {
            //map quote line item id with respective opportunity line item id
             mapSortOrder.put(qli.Id,(Id)qli.Opportunity_Line_Item_ID__c);
        } 
    }
    return mapSortOrder;
}
3
  • thanks, but i put also this for(Schema.Quote q : lstQuotesWithLineItems) { Commented Jun 28, 2018 at 9:21
  • @MarcoMoscatelli Yes, I missed that one. Still, you should change that class/variable name. It'll cause you troubles like this in the future.
    – sfdcfox
    Commented Jun 28, 2018 at 9:22
  • have you got experience with sync? let me know because this code doesn't work well. Thanks Commented Jun 28, 2018 at 9:48

You must log in to answer this question.

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