As you can see above, either you can put thin layer against external web service to do protocol conversion to support Odata (as mentioned in https://chintanblog.blogspot.com/2017/05/odataheroku-with-salesforce-integrate.html) or write the plugin in Apex.
Here we will discuss how to write External Data Service in Apex.
1) I created a sample external web service to just for the demo - It is HR service, which return list of employees, and also employees by name, account, etc..
2) As next step, we need to write
ExternalDataSourceProvider -> ExternalDataSourceConnection -> ExternalDataService
this class basically extends DataSource.Provider, and provides what capability are supported from both authentication and database support (e.g. query, update)
This class extends DataSource.Connection, and responsible for providing table structures and as well as data results which will be consumed by query associated with External Objects
3) ExternalDataService, which takes care of calling web service and returning the data needed for ExternalDataSourceConnection.
This basically :
- understand the context (name of the table, query criteria
- calls the webservice
- returns the data in List
We can see external Objects now:
Once it is done, it is ready to be tested on Account page layout, due to indirect lookup relationship, Employee external object would be available in Account Page layout.
This way we can consume external service as external object without external Odata layer.
Source Code :