Salesforce - Querying to fetch data from junction object and Accounts - salesforce

I have a junction object called "JIRA_Data" and its linked/ related to Accounts. How do I query to fetch data from this relationship. I am trying to extract id,type from Account object and Name from JIRA_Data junction object.
Could anyone assist. Thanks

You could do it multiple ways depending on how you want the data. If you query it from the parent account it would be something to the effect:
SELECT Id, Name, (Select ID, Name, Other_Parent__r.Name FROM Jira_Datas__r) FROM Account
or from the junction
SELECT Id, Name, Account.Name, Other_Parent__r.Name FROM Jira_Data__c

Related

Soql object has multiple lookups to user

Afternoon,
I am gathering data from the LiveChatTranscript and there are multiple references to user as lookup fields. How do I pick which property I want to use as my reference to user?
LiveChatTranscript properties
LastModifiedById Lookup(User)
CreatedById Lookup(User)
OwnerId Lookup(User,Group)
query
-webroot-/query/?q=select chatkey, caseid, status,requesttime, starttime, endtime,endedby,name,ReferrerUri,platform,location, waittime,body,supervisortranscriptbody, case.description, ownerid,ownerid.user.alias?? from livechattranscript where chatkey = '12345'
In this case, owner is the field name. It looks up to the user object. No need to include the object name there. Just drop the id potion for ownerid.
Use owner.alias.

SQL Server view for PII and Non PII end user

I have situation where I need to create a view which will be used by end user who may have PII and NON-PII permission clearance controlled by AD groups.
Say i have dim_customer which contains four columns ID, Name, DoB, Country. When PII user runs
Select ID, Name, DoB, Country FROM dim_customer
the pii user should get
ID NAME DoB Country
1 John 1999-10-10 US
If the same query is run by NON-PII user then they should get
ID NAME DoB Country
1 PII DATA PII DATA US
So basically same view object is used but data is displayed according to the pii clearance.
I dont want to create two views with pii and non-pii suffix.
I tried column level permission but that means when end user try the above
query they get error "no select permission on Name and DoB Columns"
I have tried Data Masking but that shows "XXXX" and i would prefer "PII
Data".
I am looking for a solution where the query runs successfully and show results as above.
Is this possible in SQL Server ?
thanks in advance
Create two roles, one that allows PII data, and one that doesn't. Put each user into one role or the other. Than write your view
Select
ID,
Name,
CASE
WHEN IS_ROLEMEMBER ('pii_role') = 1 THEN DoB
ELSE 'PII Data'
END as DoB,
Country
FROM dim_customer

Salesforce Cross Object SOQL Query

I have a custom object called 'Billings'. On that object there is a custom lookup field to the Opportunity. I'm trying to query all the 'Billings' records associated with a particular Opportunity. I get "Unknown error parsing query".
SELECT Id, StageName,
( SELECT Name, Email FROM Billings__C )
FROM Opportunity WHERE Opportunity ID = '0011000002mfTil'
For Nested Queries in SOQL, you need to use the '__r' suffix on the Child Relationship Name for the field that provides the look-up from the Child Record to the Parent.
In your case, this is most likely 'Billings__r'. However, to confirm, go to the Billings object and click on the custom field that provides the lookup to the Opportunity object. In the "Lookup Options" section on the Custom Field details screen you will see the official Child Relationship Name without the '__r' suffix. This is the correct name for this relationship for a Nested Query.
The other error in your query is that you have "WHERE Opportunity Id =". It should just be "WHERE Id ="
Based on the information you provided, your query should be:
SELECT Id, StageName, ( SELECT Name, Email FROM Billings__r ) FROM Opportunity WHERE ID = '0011000002mfTil'

replicating master tables mapping in transaction tables

I have three master tables for location information
Country {ID, Name}
State {ID, Name, CountryID}
City {ID, Name, StateID}
Now I have one transcation table called Person which hold the person name and his location information.
My Question is shall I have only CityID in the Person table like this:
Person {ID, Name, CityID}'
And have view of join query which give me detail like "Person{ID,Name,City,State,Country}"
or Shall I replicate the mapping
Person {ID, Name, CityID, StateID, CountryID}
Please suggest which do you feel is to be selected and why? if there is any other option available, please suggest.
Thanks in advance.
I would just use a reference table, which will allow you to have more expandability in the future:
Person {ID, Name}
PersonLocation {PersonID, CityID}
Just pay attention to the primary key you use on the PERSON table, so you can distinguish one record from the other

Complex query possible?

I have 3 tables, a parent table and 2 child tables. Lets say Mother_c is the parent. Then Child_c and Pet_c are the 2 child tables that have master-detail relationship pointer to Mother_c.
I have the Id of one row from Child_c, I want to retrieve all the rows from Pet_c that correspond to the Mother_c of that single Child_c row.
I'm wondering if this is possible in one SOQL query?
Yes, this is totally possible with semi-join SOQL. I tested this out with the standard CRM objects like this:
SELECT Id,
(SELECT Id FROM Cases)
FROM Account
WHERE Id IN (SELECT AccountId
FROM Contact
WHERE Id = '0036000000qCwp9'
)
To walk you through this, with a given Contact id, you first find the parent Account, and then traverse back down to the child Cases. In your example with custom objects, it would be very similar, but would use the __r custom relationships names instead:
SELECT Id,
(SELECT Id FROM Pet__r)
FROM Mother__c
WHERE Id IN (SELECT Mother__c
FROM Child__c
WHERE Id = '003a000000qCwp9'
)

Resources