• Viviana Hernández Peña
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I have the following code where you are sending the payments of the invoices to all contacts associated with the account, is there any way to bring the contact that is associated with the invoice ???


                List<Contact> listofContacts = [SELECT Email FROM Contact where AccountId = :accId and Email != null];
                String[] toRecipients = new List<String> ();

                Integer count = 0;
                for (Contact oneContact : listofContacts)
                {
                    if (count > 0)
                    toRecipients.add(oneContact.Email);
                    count++;
                }

                Id orgWide = [SELECT Id FROM OrgWideEmailAddress limit 1].id;
I have the following code where you are sending the payments of the invoices to all contacts associated with the account, is there any way to bring the contact that is associated with the invoice ???


                List<Contact> listofContacts = [SELECT Email FROM Contact where AccountId = :accId and Email != null];
                String[] toRecipients = new List<String> ();

                Integer count = 0;
                for (Contact oneContact : listofContacts)
                {
                    if (count > 0)
                    toRecipients.add(oneContact.Email);
                    count++;
                }

                Id orgWide = [SELECT Id FROM OrgWideEmailAddress limit 1].id;
I have a Junction object name AcctContactAff which I use to create a many-to-many relationship between Contacts and Accounts and stores (among other things) the title of the person at the account.

Being new to SOQL I am really struggling to get the following to work:

SELECT Id, Name, NPI__c,
(SELECT Title__c FROM AcctContactAff__r)
FROM Contact

When I run this I get the error message: "Didn't understand relationship 'AcctContactAff__r' in FROM part of query call."

However, I can get the query to work when I do this:

SELECT Contact__r.id, Contact__r.Name, Title__c, Name
FROM AcctContactAff__c

I absolutely need to run the query from the Parent object not the Child object.

Can anyone tell me what is wrong with the first query statement?