--- title: JSON Salesforce objects section slug: '1785' canonical_url: https://docs.coveo.com/en/1785/ collection: index-content source_format: adoc --- # JSON Salesforce objects section In the JSON of a Salesforce [source](https://docs.coveo.com/en/246/), you can access the [**Objects** section](https://docs.coveo.com/en/1685#show-only-one-configuration-section). This section presents all the Salesforce objects and [fields](https://docs.coveo.com/en/200/) to be indexed. It's one of the main sections affected, along with the **Mappings** section, when you [customize the Salesforce source from the Coveo Administration Console](https://docs.coveo.com/en/1052#content-to-index-subtab). However, you might want to customize your source configuration further than what the **Edit** panel allows. Most of the time, this is done to [index](https://docs.coveo.com/en/204/) fields from parent or child objects without indexing the parent or child item. It can also be used to introduce polymorphic or conditional indexing, so that the indexed fields or [items](https://docs.coveo.com/en/210/) are dependent on certain fields. This article explains the structure of the JSON Salesforce source **Objects** section, so you can edit it better. ## Basic structure The **Objects** section presents all the elements from the `ObjectsToGet` section. The most important part is the `Query` element, as it lists all the objects and fields to be returned when indexing the objects. The following template is an example of the **Objects** section: ```json { "sensitive": false, "extendedData": { "Query": [ { "ObjectName": "NameOfYourObject1", "Fields": { "string": [ "FieldToIndex1", "FieldToIndex2", "FieldToIndexN" ] } }, { "ObjectName": "NameOfYourObject2", "Fields": { "string": [ "FieldToIndex1", "FieldToIndex2", "FieldToIndexN" ] } } ] } } ``` In this template, replace the following values with your desired ones: * `NameOfYourObject1` and `2` with the name of an object you want to index. * `FieldToIndex1` through `N` with all the object fields you want to index. > **Note** > > When manually adding Objects and Fields to index in the JSON, remember to [add mappings](https://docs.coveo.com/en/1640/) to your objects. ## Introducing parent relationships Parent relationships let you index fields from a parent object without having to index the object itself. The following template is an example of a parent relationship: ```json "Query": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "ParentRelationships": { "ParentRelationship": [ { "RelationshipName": "ParentObject", "Fields": { "string": [ "ParentObjectFieldToIndex1", "ParentObjectFieldToIndex2", "ParentObjectFieldToIndexN" ] } } ] } } ] ``` In this template, replace the following values with your desired ones: * `NameOfYourObject` with the name of an object you want to index. * `FieldToIndex` with the object fields you want to index. * `ParentObject` with the parent object from which you want to index fields. * `ParentObjectFieldToIndex1` through `N` with all the parent object fields you want to index. **Example** You want to index your cases, but not your accounts. However, you still want to have the account name in the case fields. In the JSON, in the `Query` element, you enter the following: ```json "Query": [ { "ObjectName": "Case", "Fields": { "string": [ "CaseNumber", "Description", "Subject" ] }, "ParentRelationships": { "ParentRelationship": [ { "RelationshipName": "Account", "Fields": { "string": [ "Name" ] } } ] } } ] ``` Remember to add a `%[Account.Name]` [mapping](https://docs.coveo.com/en/1640/) to your object. > **Note** > > Inside the query of your parent relationship, you can add parent relationships, polymorphic relationships, or [conditional indexing](https://docs.coveo.com/en/2006#add-conditional-indexing-for-a-salesforce-source). > > Add it after the **Fields** declaration, as such: > > ```json "Query": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "ParentRelationships": { "ParentRelationship": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "ParentRelationships": ... } ] } } ] ``` ## Introducing child relationships Child relationships, like parent relationships, let you index fields from a child object without indexing the child itself. The following template is an example of a child relationship: ```json "Query": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "ChildRelationships": { "ChildRelationship": [ { "RelationshipName": "ChildObject", "Fields": { "string": [ "ChildFieldToIndex1", "ChildFieldToIndex2", "ChildFieldToIndexN" ] } } ] } } ] ``` In this template, replace the following values with your desired ones: * `NameOfYourObject` with the name of an object you want to index. * `FieldToIndex` with the object fields you want to index. * `ChildObject` with the child object from which you want to index fields. * `ChildFieldToIndex1` through `N` with all the child object fields you want to index. **Example** You want to index your cases, but not your case comments. You however want the body of the case comment indexed as a field part of your cases. In the JSON, in the `Query` element, you enter the following: ```json "Query": [ { "ObjectName": "Case", "Fields": { "string": [ "CaseNumber", "Description", "Subject" ] }, "ChildRelationships": { "ChildRelationship": [ { "RelationshipName": "CaseComments", "Fields": { "string": [ "CommentBody" ] } } ] } } ] ``` Remember to add a `%[casecomments.commentbody]` [mapping](https://docs.coveo.com/en/1640/) to your object. > **Note** > > Inside the query of your child relationship, you can add parent relationships, polymorphic relationships, or [conditional indexing](https://docs.coveo.com/en/2006#add-conditional-indexing-for-a-salesforce-source). > > Add it after the **Fields** declaration, as such: > > ```json "Query": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "ChildRelationships": { "ChildRelationship": [ { "ObjectName": "CaseComments", "Fields": { "string": [ "CommentBody" ] }, "ParentRelationships": ... } ] } } ] ``` ### Creating records from children fields The `CreateRecord` option lets you create an item from the children fields you index. As a Boolean option, it can either be set to `true` or `false`. Its default value is `false`. The following template is an example of how to use the `CreateRecord` option: ```json "Query": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "ChildRelationships": { "ChildRelationship": [ { "RelationshipName": "ChildObject", "Fields": { "string": [ "ChildFieldToIndex1", "ChildFieldToIndex2", "ChildFieldToIndexN" ] }, "CreateRecord": true } ] } } ] ``` ## Introducing polymorphic relationships Polymorphic relationships let you index different fields depending on which object is returned. See [Understanding Relationship Fields and Polymorphic Fields](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_and_polymorph_keys.htm) for details. The following template is an example of a polymorphic relationship: ```json "Query": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "PolymorphicRelationships": { "PolymorphicRelationship": [ { "RelationshipName": "FieldToCheck", "ObjectName": "ConditionObject", "Fields": { "string": [ "ConditionObjectFieldtoIndex1", "ConditionObjectFieldtoIndex2", "ConditionObjectFieldtoIndexN" ] } }, { "RelationshipName": "FieldToCheck", "ObjectName": "ConditionObject", "Fields": { "string": [ "ConditionObjectFieldtoIndex1", "ConditionObjectFieldtoIndex2", "ConditionObjectFieldtoIndexN" ] } } ] } } ] ``` In this template, replace the following values with your desired ones: * `NameOfYourObject` with the name of an object you want to index. * `FieldToIndex` with the object fields you want to index. * `FieldToCheck` with the field whose object needs to be checked. * `ConditionObject` with the object which `FieldToIndex` field should be part of. * `ConditionObjectFieldtoIndex1` through `N` with all the fields you want to index from the condition object. **Example** When indexing your events, you want to index different fields depending on whether the `what` field is an `Account` or an `Opportunity`. When the `Event` is related to an `Account`, you want to index its `NumberOfEmployees` field, and when the event is an `Opportunity`, you want to index its `Amount` field. In the JSON, in the `Query` element, you enter the following: ```json "Query": [ { "ObjectName": "Event", "Fields": { "string": [ "Subject" ] }, "PolymorphicRelationships": { "PolymorphicRelationship": [ { "RelationshipName": "What", "ObjectName": "Account", "Fields": { "string": [ "NumberOfEmployees" ] } }, { "RelationshipName": "What", "ObjectName": "Opportunity", "Fields": { "string": [ "Amount" ] } } ] } } ] ``` Remember to add a `%[what_account.numberofemployees]` and a `%[what_opportunity.amount]` [mapping](https://docs.coveo.com/en/1640/) to your object. > **Note** > > You can add parent or child relationships in your polymorphic relationships, by using the following syntax: > > ```json "Query": [ { "ObjectName": "NameOfYourObject", "Fields": { "string": [ "FieldToIndex" ] }, "PolymorphicRelationships": { "PolymorphicRelationship": [ { "RelationshipName": "FieldToCheck", "ObjectName": "ConditionObject", "Fields": { "string": [ "ConditionObjectFieldtoIndex1", "ConditionObjectFieldtoIndex2", "ConditionObjectFieldtoIndexN" ] }, "ParentRelationships": { "ParentRelationship": [ { "RelationshipName": "ParentObject", "Fields": { "string": [ "ParentObjectFieldToIndex" ] } } ] } }, { "RelationshipName": "FieldToCheck", "ObjectName": "ConditionObject", "Fields": { "string": [ "ConditionObjectFieldtoIndex1", "ConditionObjectFieldtoIndex2", "ConditionObjectFieldtoIndexN" ] } } ] } } ] ``` ## Introducing conditional indexing > **Tip** > > You can add [conditional indexing](https://docs.coveo.com/en/1052#add-a-condition) directly from the Salesforce source configuration. > > To prevent potential issues and source configuration errors, you're encouraged to use the source configuration page instead of editing its JSON. The Salesforce source lets you index items only when they meet specific conditions, which can reduce the size of your index. To do so, enter the condition in the source JSON in the `ObjectsToGet` element. It must be included as part of the object you want to index conditionally, after its field declaration. There are two ways to add conditional indexing for a Salesforce source: * **QueryCondition**: Lets you change the operator used in the created SOQL query. * **InConditionValue**: Lets you list the allowed values in the created SOQL query. ### QueryCondition The _QueryCondition_ element lets you index items that answer to a specific query. The conditions must respect the following template: ```json "Query": [ { "ObjectName": "Object", "Fields": { "string": [ "ObjectField" ] }, "Conditions": { "queryConditionOrQueryCondition2OrInCondition": [ { "QueryCondition": { "Field": "FieldToCheck", "Operator": "OperatorToUse", "Value": "ValueToMatch" } } ] } } ] ``` In this template, replace the following values with your desired ones: * **Object** and **ObjectField**: The Salesforce object and its fields to index. * **FieldToCheck**: The Salesforce field the source should check for the matching value. The field must be one of the fields specified in your object, or the source will fail to build. * **OperatorToUse**: The [operator](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm) you want to use when comparing your field to its value. The accepted values are `=`, `!=`, `>`, `<`, `+<=+`, `>=`, `Like`, `NotLike`, `Includes`, and `Excludes`. * **ValueToMatch**: The value the field must have to be indexed. String values must be between double and single quotes (for example, `"'Phone'"`). Boolean and Date values must be in double quotes (for example, `"true"`, `"2017-06-01T00:00:00.0000000-00:00"`). It results in the following query: ```sql SELECT ObjectField FROM Object WHERE FieldToCheck OperatorToUse ValueToMatch ``` > **Note** > > You can decide to add several `QueryCondition` one after the other, inside the `queryConditionOrQueryCondition2OrInCondition` element. > The resulting SOQL query simply adds `AND` to every condition. **Example** For your Salesforce source, you want to index **Cases** only when their **Origin** field isn't **Phone**. In the JSON of the source, as part of the `ObjectsToGet` element, you have the following elements: ```json "Query": [ { "ObjectName": "Case", "Fields": { "string": [ "Origin" ] }, "Conditions": { "queryConditionOrQueryCondition2OrInCondition": [ { "QueryCondition": { "Field": "Origin", "Operator": "!=", "Value": "'Phone'" } } ] } } ] ``` This results in the following query: ```sql SELECT Origin FROM Case WHERE Origin != 'Phone' ``` ### InCondition The _InCondition_ element lets you index items only when one of their field has a specific value from your listed values. The condition must respect the following template: ```json "Query": [ { "ObjectName": "Object", "Fields": { "string": [ "ObjectField" ] }, "Conditions": { "queryConditionOrQueryCondition2OrInCondition": [ { "InCondition": { "Field": "FieldToCheck", "InConditionValue": { "name": "AllowedValues", "declaredType": "com.coveo.cloud.source.model.sourceconfig.salesforce.generator.AllowedValues", "scope": "javax.xml.bind.JAXBElement$GlobalScope", "value": { "ConditionValue": [ { "name": "FieldType", "declaredType": "java.lang.String", "scope": "javax.xml.bind.JAXBElement$GlobalScope", "value": "ValueToMatch", "nil": false } ] }, "nil": false } } } ] } } ] ``` In this template, replace the following values with your desired ones: * **Object** and **ObjectField**: The Salesforce object and its fields to index. * **FieldToCheck**: The Salesforce field the source should check for the matching value. The field must be one of the fields specified in your object, or the source will fail to build. * **FieldType**: The type of the field to check. The accepted values are: ** `SoqlString`: a string. ** `SoqlBoolean`: a Boolean value. ** `SoqlDateTime`: a date. The format must respect the [SOQL date format](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm). * **ValueToMatch**: The value the field must have to be indexed. Ensure that the value is still in quotes, even for Boolean values. It results in the following query: ```sql SELECT ObjectField FROM Object WHERE FieldType IN ('ValueToMatch') ``` **Example** For your Salesforce source, you want to index **Cases** only when their **Status** field is either **Escalated** or **Closed**. In the JSON of the source, as part of the `ObjectsToGet` element, you have the following elements: ```json "Query": [ { "ObjectName": "Case", "Fields": { "string": [ "Status" ] }, "Conditions": { "queryConditionOrQueryCondition2OrInCondition": [ { "InCondition": { "Field": "Status", "InConditionValue": { "name": "AllowedValues", "declaredType": "com.coveo.cloud.source.model.sourceconfig.salesforce.generator.AllowedValues", "scope": "javax.xml.bind.JAXBElement$GlobalScope", "value": { "ConditionValue": [ { "name": "SoqlString", "declaredType": "java.lang.String", "scope": "javax.xml.bind.JAXBElement$GlobalScope", "value": "Escalated", "nil": false }, { "name": "SoqlString", "declaredType": "java.lang.String", "scope": "javax.xml.bind.JAXBElement$GlobalScope", "value": "Closed", "nil": false } ] }, "nil": false } } } ] } } ] ``` This results in the following query: ```sql SELECT Status FROM Case WHERE Status IN ('Escalated', 'Closed') ```