• satch
  • 0 Points
  • Member since 2012

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 1

I'm trying to grab all the notes for every contact associated with an account. I built a controller to do it:


public class aggregateNotes{
    private Opportunity opp;
    public aggregateNotes(ApexPages.StandardController controller) {
        this.opp = (Opportunity)controller.getRecord();
    // container for the notes (not used, yet)
    public class row {
        public string LastName {get; set;}
        public string Body {get; set;}
        public row(sObject o){
            LastName = (String)o.get('LastName');
            Body = (String)o.get('Body');
    public List<row> getRelatedNotes(){
        // get the account id from the opportunity
        opp = [SELECT id, Account.id FROM Opportunity WHERE id = :opp.id];
        List<row> rows = new List<row>();
        for(sObject o : [SELECT LastName, (SELECT Body FROM Notes) FROM Contact WHERE Account.Id = :opp.Account.id]){
            // this fails! WTF?
        return rows;


I get a "System.SObjectException: Invalid field Body for Contact" on the System.debug(o.get('Body')) call. How do I access the body field in that SOQL?

  • May 25, 2012
  • Like
  • 0

I'm following the documentation on updating an object with a relationship field, but I'm getting an error. The documentation says to format the xml as such when referring to a relationship field:




In my case the xml looks something like this:



<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload">
    <Name>My Location</Name>


This is an attempt to upsert to a custom object (Location__c) with an external id api name of 'location_external_id__c' that has a text field called 'name' and a Master-Detail(Account) field with relationship name 'Account__r'.  Account has an external id field called account_external_id. As far as I can tell this is all following the documentation for the bulk api. However I get back an error like this:


<results xmlns="http://www.force.com/2009/06/asyncapi/dataload">
      <message>Location__c: bad field names on insert/update call: Account_r, sObject, account_external_id__c</message>


This looks to me like the Bulk API doesn't know anything about relationship fields despite what the documentation clearly says. Hopefully I'm just doing something wrong, does anyone have any ideas?