SalesForce SOQL join Leads to Contact - salesforce

I'm trying to query data out of SalesForce Lead using SOQL and JOIN and obtain contact information where for the Lead Created through the contacts object.
I'm not sure which objects to use how to go about doing it.
Does anyone know of a detail schema of what can be used with SOQL relationship queries.
I've tried some examples from the following links but don't know how to do the same with Leads, contacts:
https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html

First of all you didnt mention properly what you want
List<lead> info = [Select * from Lead where Id = 'Id name of that Particular record of lead'];
system.debug(info);
now you can see all information of that particular lead in logs.

Related

SOQL query doesn't retrieve all contacts

I am working on a code snippet that is supposed to import all my contacts from Salesforce via SOQL.
Here is what I do when I want to import all Salesforce contacts for my user 00520000001IbXZAA0
First SOQL:
SELECT Id FROM account WHERE ownerid = ‘00520000001IbXZAA0’
Then I get all the account id where I am a team member:
SELECT AccountId FROM accountteammember WHERE UserId = ‘00520000001IbXZAA0’
Then I build an array with my ids and from my 2 previous requests and get all contacts this way:
SELECT FirstName, LastName, Account.Name FROM Contact WHERE AccountId IN myarrayofids ORDER BY CreatedDate ASC
This approach seems to get most of my contacts but I can still see some contacts appear in Salesforce but that are not retrieved with these 3 queries. Am I missing something here?
I have only very few knowledge of how Salesforce work but I suppose that if I retrieve all contacts where I am a team member or owner, I should retrieve all contacts I am able to see on Salesforce or am I missing something here?
Many thanks
The reason you are not able to see all records otherwise is as some might be shared with you via OWD or using role based sharing, manual sharing or apex sharing. If you are just looking for a list in csv or anything, the easiest thing you can do here is create a report to display all contacts and share it with this user. Login into Salesforce as this "00520000001IbXZAA0" user. Run the report and export into csv/excel.
If you wish to do this in code, write a class using "with sharing" keyword and run the following query "Select Id, FirstName, LastName .... From Contact". This will return this user all the records she/he has access to.
Try these above solutions and let me know if they work for you. Happy to help..!!

Join User and LoginHistory in SalesForce?

I am unable to get the user information from LoginHistory object.
I tried using this
SELECT User.FirstName FROM LoginHistory
but not it says
INVALID_FIELD:
SELECT User.FirstName FROM LoginHistory
^
ERROR at Row:1:Column:8
Didn't understand relationship 'User' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
System.debug(JSON.serializePretty(LoginHistory.UserId.getDescribe())); shows "null" as the "relationshipName". Not all relations allow going "up" this way, you can check my answer https://salesforce.stackexchange.com/a/23507/799 for some examples.
You'll need to make-do with two separate queries. There's equally no way to reverse it because the related list doesn't have name either. This won't work:
SELECT FirstName,
(SELECT Id FROM LoginHistories LIMIT 10)
FROM User
LIMIT 10
Maybe there's an idea you can upvote? Maybe you'll have more luck with Event Monitoring. Haven't used it personally but my understanding is it can track login, logout, exporting a report... Might be easier to query.

Querying Salesforce Activity History using Power Query raises DataSource.Error

I think what I am doing is quite simple but hitting an unexpected error.
When I navigate the Salesforce.com Object Database using Power Query, and attempt to access the Activity History table I receive the following error.
DataSource.Error: entity type OpenActivity does not support query
Details:
List
Is there such thing as unqueryable tables from Salesforce Object Library or can I access the table using a different method in PowerQuery? List doesn't seem to work...
let
Source = Salesforce.Data("https://login.salesforce.com/", [CreateNavigationProperties = true]),
SFDC_ActivityHistory = SFDC{[Name="ActivityHistory"]}[Data]
in
SFDC_ActivityHistory
I do my usual login and then provide organization wide security credentials. Other tables work fine like accounts and opportunities.
ActivityHistory Table cannot be accessed directly, but you could get query access to it as the child relationship of a primary object. For instance:
Select Name, (Select Subject, ActivityType from ActivityHistories) from Account
Please refer to the last section, "Usage", of the document: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_activityhistory.htm

SOQL query to get member data of members in a specific case team

I want to get the Member information for the members of a Case Team. Is there anyway to do this without making multiple queries? It doesn't look like this data is associated with the record in the table CaseTeamMember.
Turns out you can do this (for some reason)
[select MemberId, Member.Name from CaseTeamMember where ParentId = '<Your Case Team Id`>]
I don't know if I'm missing something but this wasn't apparent from what I read in the documentation. I'm putting this here hoping it will help someone.

Salesforce SOQL Queries and Tags

I'm just getting started with the Salesforce Web Services API and I'm surprised that there isn't an obvious way to do a query for all e.g. Account objects that contain certain tags.
What would you say is the best way to find all objects that contain certain tags?
I imagine it involves a join on Account.id and AccountTag.id or something similar, but despite some real research, I'm not sure how best to solve this problem.
Thanks in advance!
Update: I guess I could do a select from AccountTag and then get the account objects based on ItemId, but the ideal would be to do a query on Account, with Tags being only one part of the criteria.
You can use the SOQL-R style queries to do this, e.g. this will fetch the account Id and account Name for all the accounts with the internet tag.
select item.id, item.name from accountTag where name='internet'
in this case the item relationship is to the account that was tagged, so you can select any field from the account object through the item relationship path.
See the SOQL-R docs for more info

Resources