• tschatz
  • NEWBIE
  • 5 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 28
    Replies
Hi All,
 
I'm really banging my head with this one. I understand why I'm getting the error. My code is making too many SOQL queries. I've read the reference manual and understand that in some way I need to use Sets and Maps to get around making so many SOQL calls, but for the life of me, I can't figure out how to work this in to my code. To me it seems that I need to make one SOQL call to get a piece of information that I need to make the next SOQL call and so forth. Could someone PLEASE look at my code and show me using my code how I could change this to avoid the too many SOQL queries error? I've seen examples of how it's done but can not apply that to my code. My brain is not working in that direction so please don't point me to other examples. I'm not getting it.
 
Thank you in advance for your much appreciated help.
 
_t
 
Code:
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;
        }
      }
    }
  }
}

 

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

How do I remove triggers created with Eclipse? I delete them from Eclipse but they are still on the Salesforce instance.
 
I have reverted to removing the content from the triggers so they don't do anything, but they are still there firing.
 
Thanks.
 
_t
Hi All,
 
I have created a trigger and class that populates a field on the Account when a Contact is edited, but I really want this to be triggered when a Contact is added to a Campaign.
 
I tried adding a trigger to the CampaignMembership object but it tells me that triggers can't be added to this object.
 
Which object should I add the trigger to in order to update the Account field when a Contact is added to a Campaign?
 
I guess the question could also be, is a Contact added to a  Campaign or is a Campaign added to a Contact?
 
Thanks in advance.
 
_t
Hi All,
 
I've set up a Workflow and Outbound Message to fire when a Contact is added or updated. I know the workflow works because I also update a field when the workflow fires and that works.
 
I looked in the outbound message queue and the message has this error: org.xml.sax.SAXParseException: Content is not allowed in prolog.
 
What does this mean?
 
I'm calling a Webservice and sending it the value of a field on the Contact object.
 
Thanks in advance.
 
_t
 
 
I have a trigger on the Opportunity Object that calls a class. That class then calls another class that makes an HTTP GET request to a Web Service.
 
However I get the error:
 
Callout from triggers are currently not supported.
 
How can I send data to an external Web Service using Apex code? I have read (or am reading) chapter 12 of the reference manual, but obviously missing something.
 
Help please.
 
_t
 
How do I get a list of Products associated with an Opportunity through the API?
 
It seems that they are connected via PriceBookEntries, but a query of the OpportunityLineItems returned no PriceBookEntry IDs.
 
Any thoughts?
 
Thanks in advance for your help.
 
_t
What path should I take to get a Product ID from an Opportunity? I've looked at the API and it seems to state that the PriceBookLineItem should contain the Product ID.
 
I have tried this:
 
Code:
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:
 
Error: Invalid Data.
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
 
Any help is appriciated.
 
Thanks.
 
_t
Hi All,
 
I'm new and hoping someone can help me along. I've created a trigger that fires when an Opportunity is added or updated. It calls a class method that I have created.
 
The method checks to see if the Stage field is set to Closed Won, if it is the method does things. So far this is working as long as I don't have the method do to much. Basically I have it add an error to the page so I could see that it is firing, which it is.
 
Here's what I'm looking to do, when an Opportunity Stage is set to Closed Won, I want to find the First Name, Last Name, and Email Address of the Contact with the Contact Role of 'Ship To' (a custom role set in Salesforce) for that Opportunity.
 
Here's what I have in my Class so far:
 
Code:
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];
I'm trying to get the ContactID of the Ship To person so I can access that person's Contact information, but I'm unsure how to get there.
 
Any help is appriciated.
 
_t
I have Eclipse 3.3.1 and am trying to view the salesforce schema. The instructions tell me to open a project and double click the salesforce schema file, which seems to be located under the s-controls, but there is no salesforce schema file there.
 
What am I doing wrong? Where can I find this file? How can I view the schema? Or an alternative solution to view the data structure for my salesforce instance.
 
Thank you.
 
_t
Hi All,
 
I'm sure this has been asked before, but I was unable to find a clear answer.
 
I'm trying to create a workflow that needs to validate information across multiple objects. For example if field x in the opportunity object = true and field y in the account object = true then do this.
 
Is this possible? It seems that I can not work across multiple objects. If this is not possible through the interface, has anybody done anything like this in any other way? If so, how?
 
Thanks.
 
_t
Hi All,
 
I've set up a Workflow and Outbound Message to fire when a Contact is added or updated. I know the workflow works because I also update a field when the workflow fires and that works.
 
I looked in the outbound message queue and the message has this error: org.xml.sax.SAXParseException: Content is not allowed in prolog.
 
What does this mean?
 
I'm calling a Webservice and sending it the value of a field on the Contact object.
 
Thanks in advance.
 
_t
 
 
Hi All,
 
I'm really banging my head with this one. I understand why I'm getting the error. My code is making too many SOQL queries. I've read the reference manual and understand that in some way I need to use Sets and Maps to get around making so many SOQL calls, but for the life of me, I can't figure out how to work this in to my code. To me it seems that I need to make one SOQL call to get a piece of information that I need to make the next SOQL call and so forth. Could someone PLEASE look at my code and show me using my code how I could change this to avoid the too many SOQL queries error? I've seen examples of how it's done but can not apply that to my code. My brain is not working in that direction so please don't point me to other examples. I'm not getting it.
 
Thank you in advance for your much appreciated help.
 
_t
 
Code:
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;
        }
      }
    }
  }
}

 

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

How do I remove triggers created with Eclipse? I delete them from Eclipse but they are still on the Salesforce instance.
 
I have reverted to removing the content from the triggers so they don't do anything, but they are still there firing.
 
Thanks.
 
_t
I just downloaded and installed Eclipse 3.3 and the Apex Eclipse Toolkit. I've connected several projects to different SFDC orgs, and none of them have the link to the schema explorer!?!?!?

Can anyone help me figure out how to get it to show up?
Hi All,
 
I've set up a Workflow and Outbound Message to fire when a Contact is added or updated. I know the workflow works because I also update a field when the workflow fires and that works.
 
I looked in the outbound message queue and the message has this error: org.xml.sax.SAXParseException: Content is not allowed in prolog.
 
What does this mean?
 
I'm calling a Webservice and sending it the value of a field on the Contact object.
 
Thanks in advance.
 
_t
 
 
I am writing a query in an Apex Code method and I want to make sure that there is at least one element retrieved before I start accessing elements by index. I tried .length, .count, .length() but none gave me how many elements were retrieved by the query. How can I determine if any elements were retrieved by the query? Here is my code below and thanks in advance for your help.

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

I have a trigger on the Opportunity Object that calls a class. That class then calls another class that makes an HTTP GET request to a Web Service.
 
However I get the error:
 
Callout from triggers are currently not supported.
 
How can I send data to an external Web Service using Apex code? I have read (or am reading) chapter 12 of the reference manual, but obviously missing something.
 
Help please.
 
_t
 
Hi all,

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,

We use cases pretty extensively and are in need of a solution to automatically add an activies comments to the related cases' comments. We currently do this manually but the task seems redundant. I know we need to develop a custom process that runs when the activity is saved using the API, but I cannot determine where to locate this process. If someone could point me in the right direction I would greatly appreciate it. I'm confident that with the right direction we can develop the process using the API without further support.
 
Thanks for your help.
What path should I take to get a Product ID from an Opportunity? I've looked at the API and it seems to state that the PriceBookLineItem should contain the Product ID.
 
I have tried this:
 
Code:
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:
 
Error: Invalid Data.
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
 
Any help is appriciated.
 
Thanks.
 
_t