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
Ryan PanosRyan Panos 

Will Building a "Public API" on force.com give me access to all my data on another server?

I am very excited about these two articles talking about creating “REST APIs” on top of force.com to “expose data” to . . external applications.

http://www.wadewegner.com/2013/03/creating-anonymous-rest-apis-with-salesforce-com/
http://blog.jeffdouglas.com/2013/07/02/build-a-public-api-on-force-com/

However, I had understood that you cant take data “off” of force.com.  Did I misunderstand?  If I did, then are these APIs a way to utilize data on your own external application by building an application for the native environment?

Please feel free to chastise all any misuse of any salesforce terms.  There are just so many ways to build on SalesForce, it’s very confusing!

THANK YOU!

RCP

Best Answer chosen by Ryan Panos
Vinit_KumarVinit_Kumar
I am not sure about what you meant by "cant take data “off” of force.com."

Let me try to explain how Rest API works in salesforce :-

There are 3 main methods available in Rest APIS

1.) @HttpGet : HTTP Get method is used you want to fetch data from your salesforce org in external your Application using REST API.Example would be something like below :-

2.) @HttpDelete : HTTP Delete method is used if you want to remove data from your salesforce org using Rest API.

3.) @HttpPost : HTTP Post method is used if you want to create Data in salesforce using Rest API.

Let's take an example :-

@RestResource(urlMapping='/FieldCase/*')
global with sharing class RESTCaseController {

@HttpGet
  global static List<Case> getOpenCases() {
    String companyName = RestContext.request.params.get('companyName');
    Account company = [ Select ID, Name, Email__c, BillingState from Account where Name = :companyName];
     
    List<Case> cases = [SELECT Id, Subject, Status, OwnerId, Owner.Name from Case WHERE AccountId =: company.Id];
    return cases;
    
  }
	@HttpDelete
    global static String deleteOldCases() {
    String companyName = RestContext.request.params.get('companyName');
    Account company = [ Select ID, Name, Email__c, BillingState from Account where Name = :companyName];
     
    List<Case> cases = [SELECT Id, Subject, Status, OwnerId, Owner.Name from Case WHERE AccountId =: company.Id AND Status = 'Closed'];
    delete cases;
    
    return 'Closed Cases Deleted';
  }
	@HttpPost 
     global static String createNewCase(String companyName, String caseType) {
     System.debug('COMPANY: '+companyName);
     System.debug('CASE TYPE: '+caseType);
     return “Done”;
   }
  
  }

The above class implements Rest Services for all the 3 methods.To call the HTTP Delete and HTTP Get ,your URI would be :-
   
  https://<instance name>.salesforce.com/services/apexrest/FieldCase?companyName=<any company name>,
 
  To create a new record your URI would be :-
 
   https://<instance name>.salesforce.com/services/apexrest/FieldCase/
  
   and the Post Body should have following parameters
  
   {“companyName”:”<any Name>”,”caseType”:"<any type>"}
  
   This would create a new record in your salesforce.

Hope this helps !!

If this helps,please mark this as best answer to help others :)

All Answers

Vinit_KumarVinit_Kumar
I am not sure about what you meant by "cant take data “off” of force.com."

Let me try to explain how Rest API works in salesforce :-

There are 3 main methods available in Rest APIS

1.) @HttpGet : HTTP Get method is used you want to fetch data from your salesforce org in external your Application using REST API.Example would be something like below :-

2.) @HttpDelete : HTTP Delete method is used if you want to remove data from your salesforce org using Rest API.

3.) @HttpPost : HTTP Post method is used if you want to create Data in salesforce using Rest API.

Let's take an example :-

@RestResource(urlMapping='/FieldCase/*')
global with sharing class RESTCaseController {

@HttpGet
  global static List<Case> getOpenCases() {
    String companyName = RestContext.request.params.get('companyName');
    Account company = [ Select ID, Name, Email__c, BillingState from Account where Name = :companyName];
     
    List<Case> cases = [SELECT Id, Subject, Status, OwnerId, Owner.Name from Case WHERE AccountId =: company.Id];
    return cases;
    
  }
	@HttpDelete
    global static String deleteOldCases() {
    String companyName = RestContext.request.params.get('companyName');
    Account company = [ Select ID, Name, Email__c, BillingState from Account where Name = :companyName];
     
    List<Case> cases = [SELECT Id, Subject, Status, OwnerId, Owner.Name from Case WHERE AccountId =: company.Id AND Status = 'Closed'];
    delete cases;
    
    return 'Closed Cases Deleted';
  }
	@HttpPost 
     global static String createNewCase(String companyName, String caseType) {
     System.debug('COMPANY: '+companyName);
     System.debug('CASE TYPE: '+caseType);
     return “Done”;
   }
  
  }

The above class implements Rest Services for all the 3 methods.To call the HTTP Delete and HTTP Get ,your URI would be :-
   
  https://<instance name>.salesforce.com/services/apexrest/FieldCase?companyName=<any company name>,
 
  To create a new record your URI would be :-
 
   https://<instance name>.salesforce.com/services/apexrest/FieldCase/
  
   and the Post Body should have following parameters
  
   {“companyName”:”<any Name>”,”caseType”:"<any type>"}
  
   This would create a new record in your salesforce.

Hope this helps !!

If this helps,please mark this as best answer to help others :)
This was selected as the best answer
Ryan PanosRyan Panos
Vinit-
I am very grateful for your response and I have many questions.  Please let me ask you the most important ones.

I am trying to determine if these two articles are saying that by building a spefic type of “native” app on force.com, I can make a public API that external applications can hit.  By external, I mean applications not hosted on force.com.

But please, the other key question is:

The examples you give look to be in Apex and they are utilizing the REST APIs. 

Is this use of Apex only permitted on “native” applications that are hosted on force.com?  Or is Apex also available for external applications to hit the “Open APIs” such as REST API and Bulk API?

I think part of my confusion lies in how the term “Rest API” is used in various documents.  In other parts of the software world, REST is usually means an HTTP based protocol to exchange data across different domains (and with certain formats, etc ).  However, I think Rest API in sales force might SOMETIMES refer to an optional means for native apps to retrieve salesforce data from within force.com.  Is that correct?

Thank you so much for your help,
Ryan
Vinit_KumarVinit_Kumar
Ryan,

Let me answer you one by one :-

1.)Yes,you are right you can create an App in force.com which external application(which are not hosted on salesforce.com) can hit.

2.) Apex is language dependent on Force.com platform. But,the Rest API webservices which you would create using Apex on Force.com platform can be accessible by any external application.

Hope this helps !!