• Kauser Fatima
  • NEWBIE
  • 15 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
I'm trying out a parent child relationship query for Account and Contacts.

SOQL: Select Id,Name,Description, (SELECT Id,AccountId,Email FROM Contacts WHERE Email = 'info@salesforce.com') From Account

Here my expectation would be I get only the Accounts for which the child objects email is info@salesforce.com. But Salesforce returns all the Account objects (the ones which do not satisfy the criteria for them Contacts is returned as null.)

Sample response:
{
    "totalSize": 2180,
    "done": false,
    "nextRecordsUrl": "/services/data/v40.0/query/01g1I00000SjHMFQA3-999",
    "records": [ {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v40.0/sobjects/Account/0011I000005AswhQAC"
            },
            "Id": "0011I000005AswhQAC",
            "Name": "dfs",
            "Description": null,
            "Contacts": null
        },
        {
            "attributes": {
                "type": "Account",
                "url": "/services/data/v40.0/sobjects/Account/0011I000005FA6aQAG"
            },
            "Id": "0011I000005FA6aQAG",
            "Name": "Global Media",
            "Description": "GBM is the worldwide leader in technology news and information on the Web and the producer of the longest-running and farthest-reaching television shows about technology.",
            "Contacts": {
                "totalSize": 1,
                "done": true,
                "records": [{
                    "attributes": {
                        "type": "Contact",
                        "url": "/services/data/v40.0/sobjects/Contact/0031I000003583XQAQ"
                    },
                    "Id": "0031I000003583XQAQ",
                    "LastName": "White",
                    "AccountId": "0011I000005FA6aQAG",
                    "Email": "info@salesforce.com"
                }]
            }
        },...
]

Is this expected? Or can we workaround this so that we get only those parent objects for which the child object criteria is satisfied.

Any help would be appreciated.

Thanks
While creating an Opportunity record in Salesforce via REST API, even though the values for mandatory fields are not given, Salesforce accepts it and does not throw a validation error. For Ex: Account Name is mandatory in Salesforce UI while creating an Opportunity and it doesn't allow to create until we give a value for Account Name.

However if the same request is passed via REST API it accepts it.

Here is the sample request:
POST request 
/services/data/v40.0/sobjects/Opportunity
 { "Name": "test opportunity", "StageName": "Closed Lost","CloseDate": "2018-04-02"}

This request succeeds in creating an opportunity where in actual it should have given a validation error for Account Name field.

Is this behavior expected? Any help would be appreciated. 

Thanks
While creating an Opportunity record in Salesforce via REST API, even though the values for mandatory fields are not given, Salesforce accepts it and does not throw a validation error. For Ex: Account Name is mandatory in Salesforce UI while creating an Opportunity and it doesn't allow to create until we give a value for Account Name.

However if the same request is passed via REST API it accepts it.

Here is the sample request:
POST request 
/services/data/v40.0/sobjects/Opportunity
 { "Name": "test opportunity", "StageName": "Closed Lost","CloseDate": "2018-04-02"}

This request succeeds in creating an opportunity where in actual it should have given a validation error for Account Name field.

Is this behavior expected? Any help would be appreciated. 

Thanks