1 Reply Latest reply on Sep 19, 2014 11:44 AM by Rick Bergen

    Empty streamPosition but non-zero remainingCount on getMultipleLeads call

      Hi, I made the following SOAP call -

             <env:Header>
               <ns1:AuthenticationHeader>
           <!--- Removed -->
               </ns1:AuthenticationHeader>
             </env:Header>
             <env:Body>
               <ns1:paramsGetMultipleLeads>
                 <leadSelector xsi:type="ns1:LeadKeySelector">
                   <keyType>EMAIL</keyType>
                   <keyValues>
                     <stringItem>test@test.com</stringItem>
                   </keyValues>
                 </leadSelector>
               </ns1:paramsGetMultipleLeads>
             </env:Body>
           </env:Envelope>

           This is the response I received - 

                <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.marketo.com/mktows/">
                  <SOAP-ENV:Body>
                    <ns1:successGetMultipleLeads>
                      <result>
              <returnCount>3</returnCount>
              <remainingCount>1</remainingCount>
              <newStreamPosition/>
                        <leadRecordList>
                          <!-- 3 leadRecords with email = 'test@test.com' -->
                        </leadRecordList>
                      </result>
                    </ns1:successGetMultipleLeads>
                  </SOAP-ENV:Body>
                </SOAP-ENV:Envelope>

            
      As you can see, the remainingCount is reported to be 1 but the newStreamPosition is empty. The condition I use to terminate the stream is 'remainingCount == 0'. So the empty newStreamPosition leads to an infinite loop.

      I've temporarily modified the condition to 'remainingCount == 0 OR newStreamPosition is blank'. What's going on here?
        • Re: Empty streamPosition but non-zero remainingCount on getMultipleLeads call
          Rick Bergen
          I've found that if the returnCount is less than the batchSize I can conclude that there are no more records to get despite the remainingCount being greater than zero.  The remainingCount is notoriously unreliable with the excuse being it is an "estimate".  I vaguely recall the errors in remainingCount may have something to do with Marketo including SFDC Users in their remainingCount but not at their returned results.

          This is the hack I put in my code to avoid the somewhat infinate loops I was getting:

                              if (returnCount < batchSize)
                              {
                                  remainingCount = 0;
                              }


          A better solution may indeed be to look for a blank newStreamPosition as you have suggested as I suppose having exactly a batch size of records is possible.