With APEX if you have a list of Ids like:

List<Id> customObjList

You can do one efficient SOQL query using the IN keyword.

SELECT ID,NAME from SObject WHERE Id IN :customObjList

I have to do a similar thing or something else which is efficient/best practice in JAVA.

I have an arrayList of Ids.

ArrayList<SObject> invoiceObjectlist

I am hoping I can use one SOQL query to get records with those Ids. If so how can I do this?

Thank you.


If you know their IDs and are using SOAP API , retrieve is much better than hand-crafting SOQL :)

Otherwise I'm afraid you'd have to create full query yourself, ...WHERE Id IN ('001...', '001...', '001') style

  • Very nice. retrieve() is something I was looking for. Also a quick question, I am thinking the answer is no. But when you do a mass create/Upsert you can get the IDs of the new records using getId() on the result object. Is there any way we can get the name of the record at this point as well? That would save me the retrieve() call.
    – Richard N
    Dec 17 '12 at 17:48
  • 4
    Nope only the id is available. Unless you explicitly set the name on the record. Dec 17 '12 at 18:37
  • As @techtrekker said - I'm not aware of any. You need to query to get back autonumbers, fields that got default values, were set with workflows etc... That or write an apex webservice that'd insert, query & return it for you but sounds a bit of overkill unless you're really concerned about network bandwidth, count of API calls etc.
    – eyescream
    Dec 17 '12 at 20:43
  • Ok thanks guys. Out of curiosity how would I retrieve the Name if it was being set explicitly at the time of doing the bulk Insert/Upsert call?
    – Richard N
    Dec 17 '12 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.