function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
richardfrichardf 

How do I trigger the assignment rule for a lead added from the Soap Web Service API?

I am adding leads to a specific account for distribution to the sales staff through the Soap Web Services API.  I would like to have the lead assigned to the correct sales individuals based upon the assignment rules we will create.  How do I trigger the assignment rule through the Soap Web Services API?
DevAngelDevAngel

Hi richardf,

The API makes use of Soap headers to accomplish certain functions and the lead assignment is one of these.  The header that you will use is the SaveOptions header.  This header uses 2 elements, the autoAssign (true or false) and the assignmentRuleId.  Prior to updating or creating a lead you should create this header setting autoAssign to true and the assignmentRuleId to the assignment rule that you have set as Active for lead assignment.  You will then add this header to the message in the same fashion that the SessionHeader is added.

Doing this will accomplish what you need.

Cheers

richardfrichardf

Dave:

Thanks.  Could you please post a complete soap example so I could get it just right?

Best regards,

Richard

DevAngelDevAngel

Hi richardf,

Here you go:

POST http://na1-api.salesforce.com/services/Soap/c/2.5 HTTP/1.1

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 1.1.4322.573)

Content-Type: text/xml; charset=utf-8

SOAPAction: ""

Content-Length: 856

Expect: 100-continue

Proxy-Connection: Keep-Alive

Host: na1-api.salesforce.com

 

<?xml version="1.0" encoding="utf-8"?>
   <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">;
      <soap:Header>
         <SaveOptions xmlns="urn:enterprise.soap.sforce.com">
            <autoAssign>true</autoAssign>
            <assignmentRuleId>01Q3000000001ec</assignmentRuleId>
         </SaveOptions>
         <SessionHeader xmlns="urn:enterprise.soap.sforce.com">
            <sessionId>hagxeSyNIFd9G0tAUwthOaOmNdFb9kFxHBDVxYZ1GZPgKmgohoMAPWSraWhyNkjspX8CQghhocpmVe71Xpgp5.btzKggVlhL</sessionId>
         </SessionHeader>
      </soap:Header>
      <soap:Body>
         <create xmlns="urn:enterprise.soap.sforce.com">
            <sObjects xmlns:q1="urn:sobject.enterprise.soap.sforce.com" xsi:type="q1:Lead">
               <q1:Company>Test Company</q1:Company>
               <q1:FirstName>Reef</q1:FirstName>
               <q1:LastName>Mind</q1:LastName>
            </sObjects>
         </create>
      </soap:Body>
   </soap:Envelope>

richardfrichardf

Dave:

Thanks, that helps.  Now I need to know how to get the list of assignment rules that have been created.  The docs do not

mention this <autoAssign> feature nor how to get the <assignmentRuleId>"s .  Is there additional documentation that I am missing?

Richard

RFPZone

DevAngelDevAngel

Hi richardf,

No, the doc was published prior to this feature being exposed.  The only way, currently, to obtain the id of the assignment rule is from the UI.  Click on the assignment rule and copy the id from the address box of your browser.

 

Maplesoft BISMaplesoft BIS
Hello Dave,

The current documentation says that "SaveOptions" is deprecated and "AssignmentRuleHeader" must be used instead. How can I use the AssignmentRuleHeader to trigger the assignment rule? The code I have is something similar to this:

// C# code

lead.FirstName = "John";
lead.LastName = "Smith";

AssignmentRuleHeader header = new AssignmentRuleHeader();
header.useDefaultRule = true;
binding.AssignmentRuleHeaderValue = header;

create(lead);

I tried the code above and the assignment rule did not get triggered!!

Haydar Hadi
SuperfellSuperfell
I think you need this as well.
header.useDefaultRuleSpecified = true;
Maplesoft BISMaplesoft BIS
The field "useDefaultRuleSpecified" did not exist for the header object (class:AssignmentRuleHeader)!!!

The class for this object is automatically created based on the wsdl provided in the SalesForce website. I changed the following line in the wsdl and regenerate the class:


From:
   <element name="useDefaultRule" type="xsd:boolean" nillable="true" />

To:
   <element name="useDefaultRule" type="xsd:boolean" minOccurs="0" />

After making this change in the wsdl, I recreated the class. The "useDefaultRuleSpecified" was then available for the header object of the AssignmentRuleHeader class.

At that point I add the line I was missing according to Simon's post:

    header.useDefaultRuleSpecified = true;

but the assignment rule did not get triggered!

I probably shouldn't change the wsdl file, but that was the only way I found to make the field
"useDefaultRuleSpecified" available in the class :AssignmentRuleHeader)



SuperfellSuperfell
My bad, if the specified field isn't there, then there's no point twisting the WSDL to make it appear.
SuperfellSuperfell
Are you sure that the create call is making the create call using the client stub called "binding" ?
Maplesoft BISMaplesoft BIS
That is correct. The object (binding) is the same object used for in both places:

binding.AssignmentRuleHeaderValue.useDefaultRule = true;  // trigger the assignment rule
binding.create(new sObject[] {sFObject})                  // creating the lead

Haydar
SuperfellSuperfell
Hmmm, what makes you think the default assignment rule didn't fire ?