Showing posts with label asp.net webapi. Show all posts
Showing posts with label asp.net webapi. Show all posts

Sunday, July 3, 2016

Creating custom object and consuming in webapi - Sales force

Creating custom object and consuming in webapi 

There are numbers of standard objects in Sales force. Depending on the requirement, sometime we might require to create some custom objects in sales force.

This article is all about "how we can create the custom objects in sales force and how we can consume them in asp.net webapi"

Custom Object: -

Custom objects are database tables that allow you to store data specific to your organisation in Salesforce. You can use custom objects to extend Salesforce functionality or to build new application functionality. 
Once you have created a custom object, you can create a custom tab, custom related lists, reports, and dashboards for users to interact with the custom object data. You can also access custom object data through the Force.com API.

Creating Custom Object:-

Sign-in in force.com
Move to [SetUp] >> Build >> Create >> Objects and click on "New Custom Object"

provide required details and choose from optional permission handing (i.e. enable note on record etc..) and click same



Custom objects named "MyCustomObject" is ready. You can note down the API Name for cutom objects as it will be required while querying on this objects from api.

Only following standard fields created when custom object get created 

  • CreatedBy
  • LastModifyBy
  • Name
  • Owner




Creating Custom fields:-

We had added new custom objects but that does have only standard fields yet but we require fields to store data. The user defined fields on a custom objected termed as custom fields in sales force. It is very easy to create simple field or look up field.

[Custom Fields & Relationship] >> [New]

Same we create a field/column in db, we have information 
  • what type of column it would be
  • what type on constraint can be applied on it
  • what will be length of column
  • it is be a look up column
very similar way sales force is asking detail while creating custom fields.because at the end it will be column in sales force db somewhere.



Choose data type and click next.
Set field level security in step 3 and last step show  basis detail of field , can set page layout.

View all Custom Objects:-

[SetUp] >> Build >> Create >> Objects


Performing read on custom object from web api:-


Code to access:-


namespace MyFirstSalesForceAPI.Controllers
{
    public class CustomSalesForceObjController : ApiController
    {
        private static string _consumerKey = "3MVG9ZL0ppGP5UrB3oyPJP28HLRAP8yV0mp4qqcVRgbZ7EdGT96I0t6AHO22xth8C_R8tkPI0qo270C5eH9R7";//your consumer key
        private static string _consumerSecret = "2970133464515046181";//your key secret
        private static string _userName = "sunitkanyan@sunitkanyan.in";

        private static string _securityToken = "N2fwK2ZEZBwH0blYMm4zYQptP";//your securitytoken
        private static string _password = "YourPassword" + _securityToken;



        // GET api/CustomObject/objectName
        [HttpGet]
        public IEnumerable<dynamic> Get()
        {
            var auth = new Salesforce.Common.AuthenticationClient();
            auth.UsernamePasswordAsync(_consumerKey, _consumerSecret, _userName, _password).Wait();

            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
            Task<QueryResult<dynamic>> res = client.QueryAsync<dynamic>("Select Id,Name,MyFSFApp__Email__c, MyFSFApp__Mobile__c from  MyFSFApp__Student__c");
            res.Wait();

            return res.Result.Records.AsQueryable();
        }
    }
}

Result



View in sales force


~
Technocrats

Saturday, May 28, 2016

Building WebAPI Using the Sales force Toolkit for .NET- PART 2 (Interaction with Sales force and ASP.NET WebAPI)

CRUD Operation in sales force's contact through ASP.NET WebAPI using sales force api.

if your client has apps on sales force cloud then something you may require deal with an asp.net /mobile application to interact with their sales force cloud.


This article will show you “How to perform CRUD with sales force api in asp.net”


Let's describe first the step involved:-
  • ·         Create a web api project.
  • ·         Add sales force nuget package.
  • ·         Add new api controller.
  • ·         Start developing get/add/edit/delete operation.
o   Get Operation: get all the contacts
o   Get a contact based on email id.
o   Add new contact.
o   Update contact.
o   Delete contact.


Create a web api project. >> Open visual studio 2010/2012/2013. And add empty solution. Thereafter add a web api project to it


Add sales force nuget package. >> DeveloperForce.Force





Add new API controller. >>




 Start developing get/add/edit/delete operation. >> Trying CRUD for contacts ,view your sales force cloud contact tab first as we are going to perform operations for same.

 Navigate to [Contacts]




Get Operation: get all the contacts. >>

Code:-

Result:-

Let us map result  to class object
Code:-

Result:-

Get contact based on email id. >>


Code:-
Result:-


Add new contact. >>

Code:-
Result:-

View New contact in sales force



Update contact detail. >> updating last name for contact in this example

Code:-

Result:-
View update last name in sales force


Delete contact. >>

Code:-


Result:-

Check in sales force                                                                                                                                                                                                  

compeleted crud operations for contacts similary can use same with little modification for leads opportunities, cutom reports etc..

-
Sunit
@SunitKanyan.in

How to perform CRUD with sales force api in asp.net
t