I am attempting to do a nested query on an object that has two related lists that happen to have the same relationship name. The query is always picking the related list associated with the standard object, but I want to query the list associated with the custom object. Here is the query: select ID, RecordType.Name, (select Id, Line_of_Business__c from Quotes) from Opportunity. The relationship name Quotes is associated with both the standard Quote object, (API name Quote) and a custom object, (API name Quote__c. )
The custom relationship should be named Quotes__r, you sure you have a problem?
What do you see when you run a describe (see my answer https://salesforce.stackexchange.com/a/23507/799, pick the "go down" piece) or open the object in https://workbench.developerforce.com/ ?
Related
We can add page relationship in two different ways using named relationships and pages data type which is kind of advanced content modelling in Kentico..
if we go through named relationships then we can give a meaningful relationship between to content node by providing description. So, we get a relationship name called “is related to”(example). When we use this in practice, then we get [page A] {is related to} [Page B].
if we go through pages data type then we assign some content on the form tab, records are created in the “CMS_Relationship” table as ad-hoc via the “RelationshipIsAdHoc” column and there is no relationship name for this as such. It is marked as Ad-hoc. and Relationship name is also added page type name underscore some randon guid example abc.product_3d628a37-7637-4a21-b0b4-e1dd1a00a3bc
My question is when we try to use page data type and we need to add relationship through api code, then how can we add because in kentico api to add page relationship through api code RelationShipNameID is mandatory field. We don't have this RelationShipNameID as we are not going through named relationship.
Found out the way
Need to retrieve ad-hoc relatioshipnameinfo object, e.g. like this:
string codeName = GetAdHocRelationshipNameCodeName("fillclassnamehere", field);
var relationshipNameInfo = GetRelationshipNameInfo(codeName);
and then use is with API:
RelationshipInfoProvider.AddRelationship(leftSiteId, rightSiteId, relationshipNameInfo.RelationshipNameId)
I have 2 custom objects in Salesforce.com
One is PersonAccount and one is Accounts.
Within the default "Account" object I have a field called user_id
PersonAccount acts as a junction table to link "Account" to Accounts
PersonAccount does a lookup in Person for user_id Lookup(Account)
How can I build a query to check something in Account to find all the matching items in Accounts?
Currently, Salesforce only permits a single level of nested queries. It cane be done like the following:
[SELECT ID, Name, Field1 from Object__c WHERE Id IN ( SELECT Id FROM Object2__c WHERE Field2 = 'SomeValue')]
However, with the junction object you don't actually need to use a nested query.
Unfortunately, your description isn't clear enough to understand your specific object set-up, so I am going to make some assumptions.
You have three objects, Accounts__c (your custom Accounts Objct), PersonAccount__c (your junction object), and Account (the default Account objects).
The PersonAccount__c object contains two lookup fields (for a true Junction, they should be Master-Detail). The first is to Accounts__c (we will call that lup_cust_accounts__c). The second is to Account (we will call that lup_account__c). [As an aside it is a really bad idea to have an Accounts and Account object. It is going to screw you up because Salesforce will automatically pluralize words and then you will be confused as to which is which.]
Salesforce allows dot relationship lookups in SOQL queries. So if you want to get the ID and Name from custom Accounts Objects when the associated Account object's Name is like "Test", you could do the following:
[SELECT lup_cust_accounts__r.Id, lup_cust_accounts__r.Name FROM PersonAccount__c WHERE lup_account__r.Name LIKE 'Test%'];
Notice the double underscore r instead of double underscore c? That is how you indicate a reference (lookup) rather than the specific field value.
I am running the following query in salesforce to get the country
SELECt name, owner.country from lead
This gives the following error:
No such column 'country' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
However this works just fine if I do
SELECt name, owner.id from lead
SELECt name, owner.username from lead
SELECt name, owner.name from lead
It gives the data
This happens due to the polymorphic relationship. If you have carefully read the error you are getting, you may have noted that the entity is Name, it's not User (as I also expected sometime back).
The Name object is used to retrieve information from related records where the related record may be from more than one object type.
For example, the owner of a case can be either a user or a group
(queue)
Who, What and Owner relationship fields will be used to access this Name object and it can't be accessed directly. And the error you are getting is due to this Name entity doesn't have a field called country as you can see in the documentation.
I have the following three custom objects:
Order__c
Design__c (has a lookup to Order and a lookup to Location, so the design ojbect is the junction object)
Location__c
On the order page layout I want to add a blank section that contains a VF page in order to display the Location records for all the design records for an order.
An order can have many designs and a design can have many locations. I need a way to group and display each design/locations in the VF page on the Order.
How can I build this query and display the results on the VF page?
I was trying a query like this: Select Location_r.Name, Location_r.Mockup From Design_c where Order_c = 'xxxxxxxxxxxxxx'
Also, is there a better way to display the results besides a VF page section in a related list?
Thanks for any help!
Regards.
First things, first. since design is related to the other 2 objects via lookup, it is not a junction object. junction objects are only when it's 2 parents have a master-detail relationship with the child.
I think what you're trying to achieve is to traverse a parent-child-parent relationship. You'll need to use subqueries for the last half. From the documentation- here you go: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm
Query **child-to-parent relationships**, which are often many-to-one. Specify these relationships directly in the SELECT, FROM, or WHERE clauses using the dot (.) operator.
For example:
SELECT Id, Name, Account.Name
FROM Contact
WHERE Account.Industry = 'media'
This query returns the ID and name for only the contacts whose related account industry is media, and for each contact returned, the account name.
Query **parent-to-child**, which are almost always one-to-many. Specify these relationships using a subquery (enclosed in parentheses), where the initial member of the FROM clause in the subquery is related to the initial member of the outer query FROM clause. Note that for subqueries, you should specify the plural name of the object as that is the name of the relationship for each object.
For example:
SELECT Name,
(
SELECT LastName
FROM Contacts
)
FROM Account
The query returns the name for all the accounts, and for each account, the last name of each contact.
Ladies and Gents, I have created a junction object (name_CallContactMap_c) that describes a many:many relationship between a custom object (call) and Contact. The object has 2 master-detail fields, one refers to a contact record and one to my custom call record. I am hoping that a call like this will work:
FIND {a0AA0000007MJkhMAG} RETURNING
name__CallContactMap__c(name__Contact__r.FirstName,name__Contact__r.LastName)
As it stands the call returns zero records and no error. There is definitely a matching record. Needless to say I can find it using SOQL, but it's the "scanning all objects at once" feature in SOSL that I want to use as there will be many different junction objects linking to many different kinds of object.
From the docs
SOSL enables you to search text, email, and phone fields for multiple objects simultaneously
The limitation you're hitting is that id fields are not considered text fields. That said your approach can work if you mirror the record id in a text field which would then be accessible in SOSL searches.
You cannot search on Id's using SOSL at the moment. You can use a SOQL to search for the the junction object. Would be curious to know why you prefer to use SOSL instead of SOQL?
Anup