Service Flow Manager > Custom Actions > Creating a Custom Action > Custom Action for Webservice > Sample Custom Apex Class to Invoke Web Service
Sample Custom Apex Class to Invoke Web Service
This is a sample Custom Action of type Webservice. Follow the instructions below to set up an SFW Action to invoke the Apex Web Service.
Create Apex Web Service
// This is a sample web service to update the ownership of given Work Order record to the current user id// This is to be configured as an SFM custom action, which in turn must be associated with a custom SFM wizard step


global class Test_CustomSFMAction


{
webservice static SVMXC.INTF_WebServicesDef.INTF_Response takeWOOwnership(SVMXC.INTF_WebServicesDef.INTF_Request request)
{
SVMXC.SFMTransactionSync sfmTxnSync = new SVMXC.SFMTransactionSync();


SVMXC.INTF_WebServicesDef.INTF_Response response = new SVMXC.INTF_WebServicesDef.INTF_Response();


try{
response.success = true;
response = sfmTxnSync.updateRecord(request, response);


// CUSTOM CODE - START


String recordId;


for(SVMXC.INTF_WebServicesDef.SVMXMap objSVXMMap : request.valueMap){


if(objSVXMMap.key == 'SVMX_RECORDID') {


recordId = objSVXMMap.value;


break;


}


}


SVMXC__Service_Order__c objWO = [Select Id, Name, OwnerId from SVMXC__Service_Order__c where Id=:recordId];


objWO.OwnerId = UserInfo.getUserId();


Update objWO;


SVMXC.INTF_WebServicesDef.SVMXMap sObj = new SVMXC.INTF_WebServicesDef.SVMXMap();


sObj.record = objWO;


response.valueMap.add(sObj);


// CUSTOM CODE - END


response = sfmTxnSync.getRecord(response);


system.debug(LoggingLevel.WARN,'response = ' +response);


return response;


}


catch(Exception ex) {


response.message = ex.getMessage();


response.success = false;


response.messageType = 'ERROR';


system.debug(LoggingLevel.WARN, 'response = ' +response);


return response;


}


}


}
Was this helpful?