You need to sign in to do that
Don't have an account?
developer-force
Using relation-ship in SOQL
I have two custom objects
City and Location. I want to create a relationship between City and Location in a manner where one city can have many locations. I have modeled this using Master-detail relationship.
On the VisualForce page I have a select list with cities and on selecting a city from the select list using actionSupport I retrieve location list corresponding to the city selected.
My Custom city object structure is as below
Location custom object
When I create a Location record instead of the City__c.id__c value a random value is stored in the Location__c.city_id__c which is relationship field.
I feel I did not understand the SObjects storage and retrieval as required. I would appreciate any help towards my understanding of the same.
City and Location. I want to create a relationship between City and Location in a manner where one city can have many locations. I have modeled this using Master-detail relationship.
On the VisualForce page I have a select list with cities and on selecting a city from the select list using actionSupport I retrieve location list corresponding to the city selected.
My Custom city object structure is as below
Code:
<—xml version="1.0" encoding="UTF-8"–> <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> <deploymentStatus>Deployed</deploymentStatus> <description>Object for city</description> <enableActivities>true</enableActivities> <fields> <fullName>city__c</fullName> <indexed>true</indexed> <label>City</label> <length>100</length> <required>true</required> <type>Text</type> <unique>true</unique> </fields> <fields> <fullName>id__c</fullName> <displayFormat>CT-{00000000}</displayFormat> <label>ID</label> <type>AutoNumber</type> </fields> <label>City</label> <nameField> <displayFormat>CT-{00000000}</displayFormat> <label>city_id</label> <type>AutoNumber</type> </nameField> <pluralLabel>Cities</pluralLabel> <sharingModel>ReadWrite</sharingModel> </CustomObject>
Code:
<—xml version="1.0" encoding="UTF-8"–> <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> <deploymentStatus>Deployed</deploymentStatus> <description>Object for location</description> <enableActivities>true</enableActivities> <fields> <fullName>city_id__c</fullName> <label>City</label> <referenceTo>City__c</referenceTo> <relationshipLabel>Locations</relationshipLabel> <relationshipName>Locations</relationshipName> <relationshipOrder>0</relationshipOrder> <type>MasterDetail</type> </fields> <fields> <fullName>id__c</fullName> <displayFormat>LC-{00000000}</displayFormat> <label>ID</label> <type>AutoNumber</type> </fields> <fields> <fullName>location__c</fullName> <indexed>true</indexed> <label>Location</label> <length>100</length> <required>true</required> <type>Text</type> <unique>true</unique> </fields> <label>Location</label> <nameField> <label>Location Name</label> <type>Text</type> </nameField> <pluralLabel>Locations</pluralLabel> <sharingModel>ControlledByParent</sharingModel> </CustomObject>
When I create a Location record instead of the City__c.id__c value a random value is stored in the Location__c.city_id__c which is relationship field.
I feel I did not understand the SObjects storage and retrieval as required. I would appreciate any help towards my understanding of the same.
developer-force
I was able to figure out the relationship and SOQL associated with it. Below is the code snippet.
Code: