[SalesForce] How to do concurrent updates/lock and update records using C#

As I understand it, I cannot use FOR UPDATE keyword when selecting records via Salesforce SOAP API (wsdl) before I update them. How do I make concurrent updates on a record retrieved via API?

Best Answer

One option would be to create your own REST or SOAP based API in Apex that would both lock and update the records required in one call. Then consume this API from C#.

SOAP based:

global class MyWebService {
    webService static Id makeContact(String lastNameParam, Account a) {

        Account lockedAccount = [Select Id from Account where Id = :a.Id FOR UPDATE];

        Contact c = new Contact(lastName = lastNameParam, AccountId = a.Id);
        insert c;
        return c.id;
    }
}

REST based:

@RestResource(urlMapping='/Contact/*')
global with sharing class ContactController {

    @HttpPost   
    global static Id makeContact(String lastNameParam, Id accountId) {

        Account lockedAccount = [Select Id from Account where Id = :accountId FOR UPDATE];

        Contact c = new Contact(lastName = lastNameParam, AccountId = accountId);
        insert c;
        return c.id;
    }
}

See Exposing Apex Methods as SOAP Web Services and Creating REST APIs using Apex REST

Related Topic