I wanted to create a blog post to remind myself how to create an Apex callout in Salesforce.com but in eClipse. I won’t get into the specifics from a step by step standpoint, but just wanted to highlight a couple things. The first is how to create a service, the second is how to create a custom data contract, the third is how to create an enumeration and expose it and lastly how to create service methods that returns a parameter. You can learn more from the Apex Developer documentation, but just thought it would be useful to show a working Apex Callout with out the details. Just remember that when you push this into your test instance of Salesforce or your sandbox, that you add test methods to test every aspect of your web service. The test coverage should be at 100% before pushing out to the production instance. That is the only way you can verify the stability of the web service.
global class VehicleService
{
//<summary>
//Created By: James Henry
//Created Date: 04/22/2011
//Name: Vehicle
//Type: Web Service Data Contract
//Description: Defines the customized automobile base class as Data Contract object
//</summary>
global class Vehicle
{
webservice int Id {get; set;}
webservice string Model {get; set;}
webservice string Type {get;set;}
webservice int Year {get; set;}
webservice int NumberOfWheels {get; set;}
webservice boolean HasDoors {get; set;}
webservice boolean HasWindows {get; set;}
webservice boolean HasTransmission {get; set;}
webservice boolean HasEngine {get; set;}
webservice SteerType SteeringType {get; set;}
}
//**********************************/
//<summary>
//Created By: James Henry
//Created Date: 04/22/2011
//Name: VehicleTypeEnum
//Type: Enmeration
//Description:
//</summary>
global enum VehicleTypeEnum
{
Automobile,
Bicycle,
Bus,
Van,
Tricycle,
Motorcycle,
Truck,
Coach
}
//**********************************/
//**********************************
//<summary>
//Created By: James Henry
//Created Date: 04/22/2011
//Name: updateVehicle
//Type: Web Service Method
//Description: Exposes a webmethod to capture Vehicle settings
//</summary>
webservice static boolean updateVehicle(Vehicle data)
{
//TODO: Perform DML functionality here.
return (data == null);
}
//**********************************
//<summary>
//Created By: James Henry
//Created Date: 04/22/2011
//Name: getVehicleInformation
//Type: Web Service Method
//Description:
//</summary>
webservice static Vehicle getVehicleInformation(VehicleTypeEnum vehicleType)
{
//TODO: Perform DML functionality here.
return [select * from Vehicle_Information__c c where c.Type = : vehicleType.trim() and c.IsDeleted = false and order by c.LastModifiedDate desc limit 1];
}
}
Comments