You need to sign in to do that
Don't have an account?
richardf
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?
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
Dave:
Thanks. Could you please post a complete soap example so I could get it just right?
Best regards,
Richard
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>
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
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.
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
header.useDefaultRuleSpecified = true;
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)
binding.AssignmentRuleHeaderValue.useDefaultRule = true; // trigger the assignment rule
binding.create(new sObject[] {sFObject}) // creating the lead
Haydar