You need to sign in to do that
Don't have an account?
Kristen Lund
Help Updating SOQL - System.SObjectException Error
Hello developers - -
A little background, we have a Design object that has a Master-Detail field of Group and Lookup field of Contact. We've created a button which allows us to email all contacts associated with a Group and it works great! However, I added another Lookup field on the Design whose email I also want to be included in this string.
I keep getting the System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Design__c.Contact2__r error, when I try to add the second contact/email field to the for loop or create a second for loop. I didn't create this and don't see the typical SOQL query fashion, so I'm not entirely sure where to add this field in order to get this second email to show up. Any ideas? Thank you in advance for any assistance!
A little background, we have a Design object that has a Master-Detail field of Group and Lookup field of Contact. We've created a button which allows us to email all contacts associated with a Group and it works great! However, I added another Lookup field on the Design whose email I also want to be included in this string.
I keep getting the System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Design__c.Contact2__r error, when I try to add the second contact/email field to the for loop or create a second for loop. I didn't create this and don't see the typical SOQL query fashion, so I'm not entirely sure where to add this field in order to get this second email to show up. Any ideas? Thank you in advance for any assistance!
global class GroupEmailListExtension { webService static String getEmailBCCList(String groupId) { String emails = ''; if(String.isBlank(groupId)) return emails; Design__c[] design= DesignHelper.FindAllByGroupIDAndStatus (groupId, DesignHelper.STATUS_CONFIRMED, true); for(Design__c des: design){ if(des.Contact__r.Email != null && !emails.contains(des.Contact__r.Email)){ emails += des.Contact__r.Email + '; '; } } return emails; } } //attempted: //1: for(Design__c des: design){ // if(des.Contact__r.Email != null && !emails.contains(des.Contact__r.Email)){ // emails += des.Contact__r.Email + '; ' + des.Contact2__r.Email + ";" ; //2: for(Design__c des: design){ // if((des.Contact__r.Email != null && !emails.contains(des.Contact__r.Email)) || (des.Contact2__r.Email != null && !emails.contains(des.Contact2__r.Email))){ // emails += des.Contact__r.Email + '; ' + des.Contact2__r.Email + ";" ;
Although I don't like that as much because we are calling Helper.getFieldsWithPrefix twice needlessly. Something like this should work but also a bit more efficient:
All Answers
Looks like the query you are looking for is in the DesignHelper class, in the FindAllByGroupIDAndStatus method. Within that method is where you can add Contact2__r.Email field.
Hope this helps!
I'm beginning to think this may just be above my head!
This should allow you to reference the Contact2__r.Email field in your getEmailBCCList method.
I realize these are usually extra spaces, but I can't seem to find any of those either. I really apprecaite the help on this!
Although I don't like that as much because we are calling Helper.getFieldsWithPrefix twice needlessly. Something like this should work but also a bit more efficient: