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
gyorkozgyorkoz 

lead create with assignment rules: setHeader() undefined method

I'm newbie and I would like to enrich my working lead-creator API with using assigment rules.

I found that I should precede the creating code with

 

$useDefaultRule = new soapval('useDefaultRule', null, 'true');
    $crmHandle->setHeader('AssignmentRuleHeader', array($useDefaultRule));

 

 

$useDefaultRule = new soapval('useDefaultRule', null, 'true');

$crmHandle->setHeader('AssignmentRuleHeader', array($useDefaultRule));

 

but it gives that setHeader() is an undefined method.

 

how could I fix the problem?

thanks for the answers

All Answers

gyorkozgyorkoz

I found out that lead creating is running without error with the next code:

 

 

$useDefaultRule = new AssignmentRuleHeader('useDefaultRule, null, 'true');
    $sfdc->setHeaders('AssignmentRuleHeader'array($useDefaultRule));

 

However the assigment rule doesn't fire, the owner stay is still the creator.

 

what's the problem??

 

Peter W.Peter W.

The PHP toolkit is generally in bad shape - including methods that seem to take assignment rul headiner info but then  ignore some of their parameters.

 

There is actually a specific method I found for setting this header - this seems to be working for me:

 

       // useDefaultRule boolean Specifies whether to use the default rule for rule-based assignment (true) or not (false).
       // Default rules are assigned in the Salesforce.com user interface.

      $header = new stdClass;
      $header->assignmentRuleId = NULL;
      $header->useDefaultRuleFlag = TRUE;
      $sfdc->setAssignmentRuleHeader($header);

Web DevelopmentWeb Development

I made a fix on the SforceBaseClient.php to allow for multiple headers.

Here is the Patch : 

50a51
>     protected $assignmentRuleHeaders;
240a242,248
>
>             $headers = $this->assignmentRuleHeaders;
>
>             if ($headers != NULL) {
>                 $header_array = array_merge($header_array, $headers);
>             }
>
340a349,371
>     public function addAssignmentRuleHeader($header) {
>         if ($header != NULL) {
>
>             if (!isset($this->assignmentRuleHeaders)) {
>                 $this->assignmentRuleHeaders = array();
>             }
>
>             $header_values = array();
>
>             if (isset($header->assignmentRuleId)) {
>                 $header_values['assignmentRuleId'] =  $header->assignmentRuleId;
>             }
>
>             if (isset($header->useDefaultRuleFlag)) {
>                 $header_values['useDefaultRule'] =  $header->useDefaultRuleFlag;
>             }
>
>             $this->assignmentRuleHeaders[] = new SoapHeader($this->namespace, 'AssignmentRuleHeader', $header_values);
>         } else {
>             $this->assignmentRuleHeaders = NULL;
>         }
>     }
>

Then you can use something like the following :

foreach($rules as $rule) {
      $ruleHeader = new stdClass();
      $ruleHeader->assignmentRuleId = $rule->id;
      $this->connection->addAssignmentRuleHeader($ruleHeader);
}

This is good for when you are dinamically reading WebForms

@ Luis A. Camilo [https://www.linkedin.com/pub/luis-camilo/13/b6b/688]