4

Need your inputs for our following requirement.

We have a team of folks who want to have a list of Cases (with selected fields) from our Salesforce instance. None of these folks have access or license in Salesforce and they have asked us to build a REST API to expose Cases from Salesforce.

Our development team is thinking of developing the following

Build a REST API (GET HTTPMETHOD)which will accept the following parameters

=> Begin Date

=> End Date

=> Queue

The objective as you can see is to provide a list of all the cases belonging to a specific case queue for a frame of time.

Questions

1) What is the maximum number of records that can be sent as Response (JSON) ?...What is the suggested limit ?

2) In a scenario where we send like 100 records to them and if they fail to receive it...what will happen and how we (Salesforce team) will know ?

3) What if they query for like 100000 records and how we can split the result set into batches and send it to them ?

2 Answers 2

5

I hope the below answers will help you to create a better solution:

  1. What is the maximum number of records that can be sent as Response (JSON) ?...What is the suggested limit ?

    Answer:
    CPU limit ,Heap size limit etc all will generally apply as same applied in normal apex class.
    Records: 50,000 records in a rest api context
    DML Statements: 150 DML
    SOQL Statements: 100 SOQL limit of context
    Response Size : 3 MB
    API Requests: Each request sent to rest apex class will count against number of API calls to your org & number of API calls allowed for your org depends on edition and as well as licenses.

  2. In a scenario where we send like 100 records to them and if they fail to receive it...what will happen and how we (Salesforce team) will know ?

    Answer: If rest service is not able to receive the request or failed, it will return the response with error message and status code.

  3. What if they query for like 100000 records and how we can split the result set into batches and send it to them ?

    Answer: I think there is no way to do this in rest API. as it returns only 50,000 records in transition. I think instead of using apex rest-api, use standard rest api to perform a query which can result in batches but for that you have to give access to your folks.

Note: As you have mentioned folks have no access or license in Salesforce, then you have to expose the rest apex class publically which can be a security breach!!

5
  • "Note: As you have mentioned folks have no access or license in Salesforce, then you have to expose the rest apex class publically which can be a security breach!!" Thanks Ajay...Is there a way to make the rest Apex class public only for Intranets or based on IP restriction ?
    – Varun
    Commented Sep 4, 2015 at 4:37
  • As rest apex classs is also secured it is not exposed direclty to user to make any http rest request, you have to login and use that generated session id to call this apex rest service.
    – Ajay Gupta
    Commented Sep 4, 2015 at 4:40
  • Great..Also if the number of records is more as Martin suggested below can we ask the folks to use curl itself ?...do they need some other access or privilege to use curl to get the list of records ?
    – Varun
    Commented Sep 4, 2015 at 4:45
  • Yes, you have to give access to your team by creating a user in salesforce having api enabled priveleges for making any standard rest api curl call to salesforce as it require authorization bearer code with is session id
    – Ajay Gupta
    Commented Sep 4, 2015 at 5:18
  • @ZenSeeker Right. To perform the query in my answer, you would need to give the api user a salesforce license. If you were going to create a custom rest resource that you made available through a force.com site, you wouldn't need to use a license, but you should be aware of how that exposes your data. You can restrict access to a force.com site by ip address, but if the information should be kept private, the most secure option is to give the api user a sf license.
    – martin
    Commented Sep 4, 2015 at 8:17
3

If you expect to have a lot of records returned, as question 3 seems to be indicating, you would probably be better off using the rest-api to directly perform a query, rather than trying to make a custom rest resource:

curl https://ap1.salesforce.com/services/data/v33.0/query?q=select+id+from+case+where+createddate+%3E+2015-08-01T00:00:00%2B00:00 -H 'Authorization: Bearer SESSIONID'

If you get enough results in the query, the query will also return a "nextRecordsUrl" that you can use to get the next batch of your results.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .