-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
11Questions
-
28Replies
Too many SOQL Queries Help Please!
public class CP_OpportunityClosedWon { public static void CP_createNewCPUser(Opportunity[] opps){ String cName; Contact c; OpportunityLineItem[] oli = new OpportunityLineItem[]{}; //initialized to fix null pointer error 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]; oli = [select id from opportunitylineitem where opportunityid = :o.Id]; } } //oli is null if the status is not shipped or definite which causes an exception here 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,name,downloadable__c from product2 where id = :pID]; if(p.downloadable__c == true){ c.Portal_User__c = true; c.Portal_URL__c = c.title; update c; } } } } }
-
- tschatz
- March 27, 2008
- Like
- 0
- Continue reading or reply
Too many SOQL queries: 21
I have done some searching and understand why I'm getting this error, but I don't understand how to work around it.
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
-
- tschatz
- January 14, 2008
- Like
- 0
- Continue reading or reply
Remove triggers created with Eclipse
-
- tschatz
- December 14, 2007
- Like
- 0
- Continue reading or reply
Populate an Account Field when a Contact is added to a Campaign
-
- tschatz
- December 14, 2007
- Like
- 0
- Continue reading or reply
Outbound Message Error: org.xml.sax.SAXParseException: Content is not allowed in prolog.
-
- tschatz
- December 11, 2007
- Like
- 1
- Continue reading or reply
Callout from triggers are currently not supported.
-
- tschatz
- November 15, 2007
- Like
- 0
- Continue reading or reply
Get Product List from Opportunity through API
-
- tschatz
- November 14, 2007
- Like
- 0
- Continue reading or reply
Getting a Product ID from an Opportunity
public class CP_OpportunityClosedWon { public static void CP_createNewCPUser(Opportunity[] opps){ for (Opportunity o:opps){ if (o.StageName == 'Closed Won') { ID cID = [select contactid from opportunitycontactrole where role = 'Ship To' AND opportunityid = :o.id].contactId; Contact c = [select id from contact where id = :cID]; OpportunityLineItem oli = [select id from opportunitylineitem where opportunityid = :o.Id limit 1]; ID pbeID = oli.priceBookEntryId; ID pID = [Select Product2Id From PricebookEntry where id = :pbeID].product2Id; Product2 p = [select id from product2 where id = :pID]; String cName = [select title from contact where id = :cID].title; if(p.downloadable__c == true){ c.Portal_User__c = True; c.tempName__c = cName; update c; } String t = pbeID; o.tempName__c = t; } } } }
And get this error:
Review all error messages below to correct your data.
Apex trigger CP_AddCPUser caused an unexpected exception, contact your administrator: CP_AddCPUser: execution of BeforeUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Class.CP_OpportunityClosedWon.CP_createNewCPUser: line 10, column 26
-
- tschatz
- November 13, 2007
- Like
- 0
- Continue reading or reply
Multiple Object Troubles
public class CP_OpportunityClosedWon { public static void CP_createNewCPUser(Opportunity[] opps){ for (Opportunity o:opps){ if (o.StageName == 'Closed Won') { Opportunity ST = [Select (Select ContactId From OpportunityContactRoles where Role = 'Ship To') From Opportunity o]; //o.StageName.addError(ST.FirstName); my failed attempt to see what is contained in ST } } } }
In the line: Opportunity ST = [Select (Select ContactId From OpportunityContactRoles where Role = 'Ship To') From Opportunity o];
-
- tschatz
- November 09, 2007
- Like
- 0
- Continue reading or reply
Troubles viewing salesforce schema w/ Eclipse 3.3.1
-
- tschatz
- November 08, 2007
- Like
- 0
- Continue reading or reply
Multiple Object Workflow
-
- tschatz
- November 02, 2007
- Like
- 0
- Continue reading or reply
Outbound Message Error: org.xml.sax.SAXParseException: Content is not allowed in prolog.
-
- tschatz
- December 11, 2007
- Like
- 1
- Continue reading or reply
Too many SOQL Queries Help Please!
public class CP_OpportunityClosedWon { public static void CP_createNewCPUser(Opportunity[] opps){ String cName; Contact c; OpportunityLineItem[] oli = new OpportunityLineItem[]{}; //initialized to fix null pointer error 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]; oli = [select id from opportunitylineitem where opportunityid = :o.Id]; } } //oli is null if the status is not shipped or definite which causes an exception here 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,name,downloadable__c from product2 where id = :pID]; if(p.downloadable__c == true){ c.Portal_User__c = true; c.Portal_URL__c = c.title; update c; } } } } }
- tschatz
- March 27, 2008
- Like
- 0
- Continue reading or reply
Too many SOQL queries: 21
I have done some searching and understand why I'm getting this error, but I don't understand how to work around it.
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
- tschatz
- January 14, 2008
- Like
- 0
- Continue reading or reply
Remove triggers created with Eclipse
- tschatz
- December 14, 2007
- Like
- 0
- Continue reading or reply
Schema Explorer missing on all projects in Apex Eclipse Toolkit
Can anyone help me figure out how to get it to show up?
- apexsutherland
- December 14, 2007
- Like
- 0
- Continue reading or reply
Outbound Message Error: org.xml.sax.SAXParseException: Content is not allowed in prolog.
- tschatz
- December 11, 2007
- Like
- 1
- Continue reading or reply
How can I determine if any elements were retrieved by the query?
Thanks,
Aref
Code:
LeadAssignment__c[] defaultLeadAssignments = [Select User__c from LeadAssignment__c where Name = '00000']; if(defaultLeadAssignments.length > 0){ defaultUser = defaultLeadAssignments[0].User__c ; }
Message Edited by aalazzani on 11-16-2007 12:27 AM
Message Edited by aalazzani on 11-16-2007 12:29 AM
Message Edited by aalazzani on 11-16-2007 12:30 AM
- aalazzani
- November 16, 2007
- Like
- 0
- Continue reading or reply
Callout from triggers are currently not supported.
- tschatz
- November 15, 2007
- Like
- 0
- Continue reading or reply
How to trigger call external application?
I have a custom object, it is named Address. When user add a record for Contact, I want to get data from MapQuest application by using Mapquest API and add data into Address.
How to do it? As I know trigger can not call S-Control, anyone can help me.
Thanks,
- tommytran
- November 14, 2007
- Like
- 0
- Continue reading or reply
Auto Case Comment
- wkirkland
- November 14, 2007
- Like
- 0
- Continue reading or reply
Getting a Product ID from an Opportunity
public class CP_OpportunityClosedWon { public static void CP_createNewCPUser(Opportunity[] opps){ for (Opportunity o:opps){ if (o.StageName == 'Closed Won') { ID cID = [select contactid from opportunitycontactrole where role = 'Ship To' AND opportunityid = :o.id].contactId; Contact c = [select id from contact where id = :cID]; OpportunityLineItem oli = [select id from opportunitylineitem where opportunityid = :o.Id limit 1]; ID pbeID = oli.priceBookEntryId; ID pID = [Select Product2Id From PricebookEntry where id = :pbeID].product2Id; Product2 p = [select id from product2 where id = :pID]; String cName = [select title from contact where id = :cID].title; if(p.downloadable__c == true){ c.Portal_User__c = True; c.tempName__c = cName; update c; } String t = pbeID; o.tempName__c = t; } } } }
And get this error:
Review all error messages below to correct your data.
Apex trigger CP_AddCPUser caused an unexpected exception, contact your administrator: CP_AddCPUser: execution of BeforeUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Class.CP_OpportunityClosedWon.CP_createNewCPUser: line 10, column 26
- tschatz
- November 13, 2007
- Like
- 0
- Continue reading or reply