Data Integration

Integration refers to the incorporation of the database into the rest of your application, the business logic, and the user interface. If your application consists solely of stored procedures, there is no integration; your code runs inside the database process and hits database objects directly. More commonly, there are application servers that need to communicate with the database.

With Force.com, either you are coding “on the platform,” which is akin to writing stored procedures, or you are developing a “composite application,” which executes somewhere else but integrates with Force.com data and logic. The following subsections describe how integrating data in Force.com differs from traditional Web application development.

Object-Relational Mapping

In traditional Web application development, one of the most important integration technologies is Object-Relational Mapping (ORM). This layer of infrastructure maps data objects from the database to and from the data structures in your program. Any ORM technology must be well integrated into your development process, efficient at runtime, and flexible in order to accommodate all data access patterns required by your application and allow for future schema changes. Java developers might use Hibernate, Ruby has ActiveRecord, and so forth.

With Force.com, the ORM layer is built in to the platform. Data objects, metadata objects, and queries have direct representation in Apex code. When you create a new custom object, it’s immediately accessible by name in Apex code. If you accidentally mistype the name of a field in your new object, your code will not compile.

For example, the snippet of Apex code in Listing 2.7 selects a single record from the Resource object, updates the value of its Hourly Cost Rate field, and commits the updated record to the database.

Listing 2.7 Apex Code Snippet


public void grantRaise(String resourceName, Decimal newRate) {
  Resource__c r = [ select Id, Hourly_Cost_Rate__c
      from Resource__c
      where Name = :resourceName limit 1 ];
  if (r != null) {
    r.Hourly_Cost_Rate__c = newRate;
    update r;
  }
}


Note the use of an in-line SOQL query (in square brackets), the custom object as a first-class object in code (Resource__c), and in-line data manipulation (update statement).

Metadata in XML

Metadata in Force.com is created using one of the platform’s Web-based user interfaces, the Force.com IDE, or the Metadata API. Unlike SQL databases, Force.com does not use Data Definition Language (DDL) but has its own XML schema for metadata. Listing 2.8 shows a simple example of Force.com’s XML metadata.

Listing 2.8 Metadata XML for a Custom Object


<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <deploymentStatus>Deployed</deploymentStatus>
    <fields>
        <fullName>Start_Date__c</fullName>
        <label>Start Date</label>
        <type>Date</type>
    </fields>
    <label>Project</label>
    <nameField>
        <label>Project Name</label>
        <type>Text</type>
    </nameField>
    <pluralLabel>Projects</pluralLabel>
    <searchLayouts/>
    <sharingModel>ReadWrite</sharingModel>
</CustomObject>


This XML describes an object with a human-readable name of Project. It contains a single custom field called Start Date, of type Date. The Sharing Model of ReadWrite means that all users in the organization can edit the records in the Project object. Force.com provides a Metadata API for importing metadata XML into the platform. This is how development tools such as the Force.com IDE operate.

Generated User Interfaces

In the process of defining a custom object, described in the next section, you will see a number of settings related to the visual appearance of your object. These settings help Force.com generate a user interface for manipulating the data in your object. From here on, this is referred to as the “native” user interface, native meaning that it is built in to Force.com.

Force.com’s native user interface is tightly integrated with your data model. The definitions of your objects, fields, and relationships are combined with additional configuration settings to create full-featured user interfaces that can perform create, read, update, delete (CRUD) operations on your data. Note that the concept of CRUD is also referred to as read, create, edit, delete (RCED) in the Salesforce world.

SOAP and REST APIs

Force.com provides SOAP and REST APIs for accessing data from outside of its platform. Using these APIs, you can run SOQL and SOSL queries, import millions of records at a time, modify records individually or in batches, and query metadata.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.214.32