Questions tagged [soql]

SOQL is the Salesforce Object Query Language.

SOQL, the Salesforce Object Query Language is a SQL like syntax used on the force.com platform to query records within a Salesforce instance. It can be used in triggers, or fully fledged Apex code, or via their web services API.

748 questions
2
votes
1 answer

Query two custom objects joining on the Name field

I want to create a join on two custom objects joining on the Name field. Normally joins require a lookup or master-detail relationship between the two objects, but I just want to do a text match. I think this is a Salesforce limitation but I…
Gerard Sexton
  • 3,114
  • 27
  • 36
2
votes
2 answers

Salesforce.com Trigger: Copy Contact Lead Source to Opportunity

I'm stuck on the syntax (and maybe the logic) of writing this Salesforce.com Trigger. I want the trigger to check to see if a primary contact is listed in the ContactRoles on the Opportunity. If there's a primary listed, I need to lookup the…
Yuengling Lager
  • 127
  • 1
  • 6
2
votes
1 answer

SOQL query that extracts data that got updated in the last x hours

I'm using CLIq and scheduled a task that is supposed to run every x-hours. My issue is that my SOQL query gets all the items from the database where I only need to extract the stuff that got updated in the last x-hours. How can I limit my query to…
raym0nd
  • 3,172
  • 7
  • 36
  • 73
2
votes
3 answers

Check for existence or catch exception?

I want to update a record if the record exists or insert a new one if it doesn't. What would be the best approach? Do a Select Count() and if comes back zero then insert, if one then query the record, modify and update, or should I just try to query…
Gerard Sexton
  • 3,114
  • 27
  • 36
2
votes
1 answer

Salesforce SOQL query length and efficiency

I am trying to solve a problem of deleting only rows matching two criteria, each being a list of ids. Now these Ids are in pairs, if the item to be deleted has one, it must have the second one in the pair, so just using two in clauses will not work.…
Bob Roberts
  • 539
  • 8
  • 22
2
votes
1 answer

SOQL query to join one-to-one between two custom objects (Salesforce Apex)

I have two custom objects in Salesforce: Object1 and Object2 Object2 has a lookup field that references to Object1. More than one record in Object2 could have the same Object1 record referenced. I have to build a SOQL query wich makes a join of…
Joaquín Fernández
  • 147
  • 1
  • 4
  • 19
2
votes
1 answer

Can you populate a set with soql?

Can you populate a set from a soql query? I couldn't get my syntax to work Set c = [select id From Contact limit 1000 ]; thanks!
PartOfTheOhana
  • 667
  • 2
  • 16
  • 40
2
votes
2 answers

Clarification on governor limits for soql queries

Setup: Say I have five Contact sObjects that I create and apex. When you insert a contact one at a time, you have x soql queries by way of triggers and stuff it uses. Questions: So if you insert each contact one at a time in your code you get 5x…
PartOfTheOhana
  • 667
  • 2
  • 16
  • 40
2
votes
2 answers

SalesForce: Query objects a user has read permission for

How can I Query all Accounts a given user has read permission for? I tried the following but, returned the error "semi join sub selects can only query id fields, cannot use: 'RecordId'" User u = new User(); Account[] account = [SELECT Name FROM…
Jon
  • 678
  • 1
  • 6
  • 9
2
votes
3 answers

SOQL query for getting contacts and leads by email

I'm trying to write a single soql query to get all contacts and leads with a particular email. Now, I'm able to write two different queries to search for contacts and leads. But is this possible using a single query(to search on multiple objects).…
Aravind
  • 221
  • 4
  • 13
1
vote
1 answer

Soql query to get all related contacts of an account in an opportunity

i have SOQL query which queries for some records based on a where condition. select id, name,account.name ... from opportunity where eventname__c='Test Event' i also need to get the related contact details for the account in the…
Prady
  • 10,978
  • 39
  • 124
  • 176
1
vote
3 answers

Query user permission level for an object's parent?

I have a custom object with a master-detail to opportunity. Is there a way to determine if the user has read or read/write access when querying this custom object? To clarify my needs, I'm looking for a way to render my page (non-visualforce) with a…
CDelaney
  • 1,238
  • 4
  • 19
  • 36
1
vote
2 answers

Salesforce and SOQL : Accessing a grandchild object from the Grandparent

I'm attempting to access a grandchild object. I have 3 Objects, Opportunity, Quote, QuoteLineItems, Opportunity is a Parent to Quote and Quote is a Parent to QuoteLineItems. Unfortunately, writing a query for this is…
Bryan Harrington
  • 991
  • 2
  • 17
  • 31
1
vote
2 answers

SOQL query to retrieve records

I need to query an object called trans__c which has the following fields id, scantime__c // datetime name asset__c // external id status I need to get only data which has status as pending and if there are any repeating asset then I need to…
Prady
  • 10,978
  • 39
  • 124
  • 176
1
vote
1 answer

How can I query records based on User permissions?

Is there a way to only return Accounts (using SOQL) that the current user has write access to? For example, if I go to a specific Account and click the [Sharing] button I can see a list of Users (and Groups) that have access to that record. When…
Matt K
  • 7,207
  • 5
  • 39
  • 60