function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohit_BatraMohit_Batra 

Multiple select queries in salesforce

Hi Community,

I have a requirement in which i want to have multiple select queries in salesforce.

For ex-> 

SELECT Name,OrderNumber__c,Description FROM Opportunity WHERE Name= 'Test-1'
SELECT Name,OrderNumber__c,Description FROM Opportunity WHERE Name= 'Test-2'
SELECT Name,OrderNumber__c,Description FROM Opportunity WHERE Name= 'Test-3'
.....And it can go upto as many as possible.

I looked everywhere in the salesforce documentation, in the SDK(DeveloperForce.force) and in the forum. But could not find any solution.

I would really appreciate it if you people could look into this and guide me to the best possible solution.
Any Lead/Help would be highly appreciated

Thanks in advance
Mohit Batra

Mohit_BatraMohit_Batra
I need to implement it via REST API
Thanks
Bhimaraj BBhimaraj B
Hi Mohit,
Instead of multiple SOQL queries, you can implement the same using below code snippet so that you will not face governor limit issues for bulk records.
Set<String> opportunityNames = new Set<String>();
opportunityNames.add('Test-1');
opportunityNames.add('Test-2');
opportunityNames.add('Test-3');
List<Opportunity> opportunities = [SELECT Name, OrderNumber__c, Description 
                                   FROM Opportunity 
                                   WHERE Name IN : opportunityNames];
I hope the above information is helpful to you!


 
Mohit_BatraMohit_Batra

Thanks for such a spontaneous reply.

Are we using WSDL for the above code snippet?

I would require results on the individual query basis as further i would be performing upsert operation on a different object using the response of my select query.

Does it makes sense to you?

Thanks

Mohit_BatraMohit_Batra
GET /composite/sobjects/Account?ids=001xx000003DGb1AAG,001xx000003DGb0AAG,001xx000003DGb9AAG&fields=id,name

I found this on the following forum:
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/using_resources_retrieve_with_externalid.htm
 
Its kind of fulfills what i am looking for. But the only problem is the data can only be fetched using ID and not other fields.
I was looking for something like
 
GET /composite/sobjects/Account?name='Test-1','Test-2','Test-3'&fields=id,OrderNumber__c

 

But could not find anything related to the above or as pe rmy requirement in rest api context which could be used
 

Bhimaraj BBhimaraj B
/services/data/v48.0/query/?q=SELECT+Id,Name,Description+from+Opportunity+WHERE+name+IN+('Test-1','Test-2','Test-3')

Can you please try like this and see?
Mohit_BatraMohit_Batra

Yes. I checked

That would solve the purpose but the records('Test-1', 'Test-2'...) might be in hundreds or even thousands.
Do you know what will be its threshold limit??

Bhimaraj BBhimaraj B
Hi Mohita,

Please find the below article for your reference.
https://salesforce.stackexchange.com/questions/195449/what-is-the-longest-uri-that-salesforce-will-accept-through-the-rest-api/195450

If you are exceeding the character’s limit then you can handle using multiple requests.

I hope the above information is helpful to you!
 
Mohit_BatraMohit_Batra

Hi Bhimaraj.

Thanks. It was really of great help.
This was my first time using this developer forum and experience was quite awesome.
Thanks once again