What are the steps to deploy rest api webservice class into production - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Chirag SapkotaChirag Sapkota 

What are the steps to deploy rest api webservice class into production

What are the steps to deploy rest api webservice class into production
Sachin DasSachin Das
Hi Chirag

What is Change Set?

Change Set is the deployment tool by which Sales force Developer/Administrator can upload/deploy the changes to Sandbox (Test Environment) to Production. You can go in Setup>Deploy>Select any option of deployment. You can deploy changes in between Sandbox to Sandbox also.

There are three main topics and steps to understand first before deployment:

1. Outbound Change set:

This is first step to the deployment through Change set. Outbound change set is nothing but creation of connection or select the changes you done in Sandbox like Object, Custom Fields, Validation, Workflow, Classes, Trigger etc. For that you have to follow below steps.

· Login in to Sandbox account of Salesforce.com.

· Go to Setup>Deploy>Outbound Change set: It will show you information on Change set and Outbound/Inbound change set information.

· Press Continue button on this page.

· Click on New button and create the outbound change set. Enter the Name of outbound change set and description of this and Click on Save.

· Once you get outbound change set detail page click Add button on Change Set Components.

· This page will show you Component Type (App, Analytical Snapshot, Apex Class, Apex Sharing Reason, Apex Trigger, Button or Link, Custom Fields, Custom Label, Object, Report Type, Custom Setting, Dashboard, Document, Email Template, Field Set, Folder, Home page Component etc.) Select any of above part and Click on Add To Change Set Button.

· After above step you will get the list of components added on change set component section.

· You can view or add dependencies in this section.

· Click on Add Profile in Profile Setting for included components means you can ass profile your can see or share the changes whatever you have done.

· After completing above steps click on Upload button. This will do the actual deployment to the Production/other Sandbox.

· Select any option from given list of Sandbox and Production.

· Click on Upload button to selected environment.

· After above step you will get Completion Email on your given email id. Means you have successfully uploaded the outbound change set.

2. Deployment Connection:

This connection step will automatically created by Sales force. Which is allows the customization to be copied from one organization to another organization. Your should be login in Production to check above list.

3. Inbound Change Set:

Inbound change set is automatically created once outbound change set it created inbound change set gets the all changes sent by outbound change set.

· Select on inbound change set and get detail of outbound.

· You can view change set components list and deployment history.

· Click on validate it will show validation history in deployment History.

· Click on Deployment after successful validation and can see Deployment History.

Note: Specific Profile Permissions control what users are able to deploy or upload change sets.

In general “Customize application” permission is required to use these features. Additonal permissions include "Manage Inbound Change Sets" and "Create and Upload Change Sets".
Enable to profile permission “Manage Inbound Change Sets” to allow users in the profile to authorize Deployment Connections to upload change sets, and deploy inbound change set to the org

Enable the profile permission “Create and Upload Change Sets” to allow user to define a change set and upload it to another org via any authorizing Deployment Connection
A Sandbox user must also exist in production in order to deploy a Change Set.  Change set deployment is not compatible with new users created in sandbox.
Make sure the user attempting to Deploy a change set exists in the production instance and is associated to a profile with permissions required to perform the function.

Please let me know if the above steps helps 

Regards
Sachin
David K. LiuDavid K. Liu
Hey Chirag,

Salesforce has an official doc for this!
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm

Basically, they created a special class that lets you "fake" a webservice call in your test class.

Hope this helps!
David
Sachin DasSachin Das
Hi

It's definitely possible to use CRUD based Metadata API calls in APEX. salesforce to salesforce and even loopback inside the same instance, we tried both.

Here's some simple code I just tested that illustrates how APEX can be leveraged to create a new custom object, just paste it into the developer console to test it:

HTTP h = new HTTP();
HTTPRequest req = new HTTPRequest();
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', 'create');

String b = '<?xml version="1.0" encoding="UTF-8"?>';
b += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
b += '<soapenv:Header>';
b += '<ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">';
b += '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>';
b += '</ns1:SessionHeader>';
b += '</soapenv:Header>';
b += '<soapenv:Body>';
b += '<create xmlns="http://soap.sforce.com/2006/04/metadata">';
b += '<metadata xsi:type="ns2:CustomObject" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">';
b += '<fullName>sample__c</fullName>';
b += '<deploymentStatus>Deployed</deploymentStatus>';
b += '<description>created by the Metadata API</description>';
b += '<enableActivities>true</enableActivities>';
b += '<label>sample Object</label>';
b += '<nameField>';
b += '<displayFormat>AN-{0000}</displayFormat>';
b += '<label>sample__c Name</label>';
b += '<type>AutoNumber</type>';
b += '</nameField>';
b += '<pluralLabel>sample Objects</pluralLabel>';
b += '<sharingModel>ReadWrite</sharingModel>';
b += '</metadata>';
b += '</create>';
b += '</soapenv:Body>';
b += '</soapenv:Envelope>';

req.setBody(b);
req.setCompressed(false);
req.setEndpoint('https://na12-api.salesforce.com/services/Soap/m/25.0');
HTTPResponse resp = h.send(req);
System.debug(resp.getBody());

you probably have to adjust the endpoint to point to your server. Using some Visualforce and a actionPoller component you can develop a nice object builder and even check if the asynchronous object creation was succussful.

Regards
Sachin
Sachin DasSachin Das
For Manual: http://www.salesforce.com/us/developer/docs/api_meta/index.htm
Shivanath DevinarayananShivanath Devinarayanan
I'd recommend using Change set, as they let you keep track of your deployments. pleae keep in mind the following
  • Make sure webservices is well tested
  • The test classes must generate their own data, event data for custom settings
  • Ensure that the EndPOint URLs are configurable 
  • Here is how you can test them : http://goo.gl/8xUIDT
  if our suggestion(s) worked,  let us know by marking the answer as "Best Answer" right under the comment.This will help the rest of the community should they have a similar issue in the future.  Thank you!

Shivanath
Chirag SapkotaChirag Sapkota
Thank you All for the quick answers. I think my question was not clear earlier. I have already tested everything realted to this Rest API class. Now I am trying to move into the production. I know about the change set, but I am trying to know following
A) Do I have to create new security Token in Production?
B) Do I have to create new OAuth as well? etc.
And what else need to be done?

If you could answer these. I will be Thankful.
 
Chirag SapkotaChirag Sapkota
Also, This Api is created to pass the information from SFDC to another Application 
David K. LiuDavid K. Liu
Hey Chirag,

Since you're passing info from Salesforce to another application, I'm guessing you don't need to store your Salesforce token or credentials in this code.

You however might need to store the tokens that connect to your other app!  If your sandbox and prod connect using the exact same login, you're good to go.

If not, I highly recommend looking into using Custom Settings to store this type of information.  Custom Settings let you update these sort of things without having to deploy any new code:
https://help.salesforce.com/apex/HTViewHelpDoc?id=cs_about.htm&language=en

Hope this helps!
David