global class MyWebService { webservice static Id makeContact(String contactLastName, Account a) { Contact c = new Contact(lastName = contactLastName, AccountId = a.Id); insert c; return c.id; } }
Generate WSDL
Apex class methods that are exposed through the API with the webservice keyword don't enforce object permissions and field-level security by default. We recommend that you make use of the appropriate object or field describe result methods to check the current user’s access level on the objects and fields that the webservice method is accessing. See DescribeSObjectResult Class and DescribeFieldResult Class.
Also, sharing rules (record-level access) are enforced only when declaring a class with the with sharing keyword. This requirement applies to all Apex classes, including to classes that contain webservice methods. To enforce sharing rules for webservice methods, declare the class that contains these methods with the with sharing keyword. See Using the with sharing, without sharing, and inherited sharing Keywords.
Create a SOAP project in SOAP UI and upload the WSDL generated above.
Following is input to invoke makeContact SOAP API defined above.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:myw="http://soap.sforce.com/schemas/class/MyWebService">
<soapenv:Header>
<myw:SessionHeader>
<myw:sessionId>session id from login output</myw:sessionId>
</myw:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<myw:makeContact>
<myw:contactLastName>Shirgaonkar</myw:contactLastName>
<myw:a>
<Id>id of account to which to connect this contact to</Id>
</myw:a>
</myw:makeContact>
</soapenv:Body>
</soapenv:Envelope>
Following would be the output:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://soap.sforce.com/schemas/class/MyWebService">
<soapenv:Body>
<makeContactResponse>
<result>0037F000027JhfYQAS</result>
</makeContactResponse>
</soapenv:Body>
</soapenv:Envelope>