• HariSubramanian
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I have done some searching and understand why I'm getting this error, but I don't understand how to work around it.

Code:
public class CP_OpportunityClosedWon {
 public static void CP_createNewCPUser(Opportunity[] opps){  
  String cName;
  Contact c;
  OpportunityLineItem[] oli;
  for (Opportunity o:opps){
   if (o.Order_Status__c == 'Shipped' || o.Order_Status__c == 'Definite') {
    
    ID cID = [select contactid from opportunitycontactrole where role = 'Ship To' AND opportunityid = :o.id].contactId;
    c = [select id, title from contact where id = :cID];
    //cName = [select title from contact where id = :cID].title;
    oli = [select id from opportunitylineitem where opportunityid = :o.Id];
   }
  }
  for (OpportunityLineItem li : oli){
   ID pID = [Select o.PricebookEntryId, o.PricebookEntry.Product2Id from OpportunityLineItem o where id = :li.id].PriceBookEntry.Product2Id;
   if(pID != null){
    Product2 p = [select id from product2 where id = :pID];
    String s = [select name from product2 where id = :pID].name;
    Boolean pd = [select downloadable__c from product2 where id = :pID].Downloadable__c;
    /*if(s !=null){
     o.tempName__c = s;
    }*/
    if(pd == true){
     c.Portal_User__c = true;
     c.Portal_URL__c = c.title;
     update c;
    }
   }
  }
 }
}


 
I'm getting the error on the line: ID pID = [Select o.PricebookEntryId, o.PricebookEntry.Product2Id from OpportunityLineItem o where id = :li.id].PriceBookEntry.Product2Id;

If I can't put a SOQL query inside of a for loop then how can I accomplish what I am trying to do here?

Any code help or code examples would be appriciated. I have already read about this in the APEX manual but am not grasping what they are saying.

Thank you in advance for your assistance.

_t