In Previous article, we have consumed the standard enterprise wsdl of the salesforce. In this article we will create the webservice using apex in salesforce and consume it in C#.Net application.
In Salesforce create below class (using force.com IDE)
global public with sharing class SaveExpenditureWebService { webservice static Expenditure__c createExpenditure(Decimal amount,String expName, String paidByName ) { Expenditure__c c = new Expenditure__c(); Person__c p = [Select p.Name From Person__c p Where Name = :paidByName limit 1]; c.Amount__c = amount; c.Name = expName; c.Exp_Date__c = Date.today(); c.Paid_By__c = p.Id; insert c; return c; } }
Note:
- Apex class in which webservice is going to be written must be declared “global“.
- Keyword “webservice“ must be used for a method which should be exposed as a webservice.
- Method must be declared as static.
In above code, I am using a custom object “Expenditure__c“ to insert into Salesforce. Any type of code can be written.
Now in C#, create windows application with following controls:

Continue reading “Create a custom Web service in Salesforce and consume it in C#.Net application”