How can we create Salesforce custom web soap service with soap header which will have wss:Security elements inside it?

following is the sample custom apex web service

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;

But how will I define custom soap header elements and ws_security elements?

1 Answer 1


Out of the box, you don't have control over the SOAP envelope. Vote for this idea.

As a workaround, you could route your web service calls through an API Gateway or similar middleware that does support WS-Security and will translate your payload. Mulesoft is a Salesforce product that can do this.

  • can we add custom headers for custom Apex soap webservice?
    – sdandamud1
    Oct 5, 2020 at 15:09
  • @sdandamud1 If you're calling a non-Salesforce, 3rd party SOAP webservice from Salesforce, you can add custom headers to your SOAP request in Apex. For SOAP webservices hosted in Salesforce (this question), you can't add headers.
    – identigral
    Oct 5, 2020 at 15:27
  • mine is Apex soap webservice created in sf and converted into wsdl , client needs to use that wsdl and add specific headers then make a request to salesforce. here is my question salesforce.stackexchange.com/questions/321516/…
    – sdandamud1
    Oct 5, 2020 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .