Specifying the Sort Order and Sort Sequence

You can specify the sort order and sort sequence for returned records using the sortorder and sortsequence arguments respectively.

The sortorder and sortsequence arguments are specified as attributes of a FieldName element in requests, for example:

<CampaignName sortorder= "ASC " sortsequence= "1 "/>

which specifies that the records returned are sorted on the CampaignName field in an ascending order.

The sortsequence argument is used to specify the order in which sorting is applied if a sortorder value is specified on more than one field, for example:

<CampaignName sortorder= "ASC " sortsequence= "1 "/>
<Status sortorder= "ASC " sortsequence= "2 "/>"

Examples of sortorder and sortsequence usage are given in the following table.

Note: The sortorder argument is not supported for fields of date type CLOB or BLOB. Such fields could be used with the searchpsec argument with a LIKE operator, however, for performance reasons, use of CLOB and BLOB fields even for filtering must be avoided.Using multiple sort criteria might affect query performance. Use it only when necessary.

Table Sortorder and sortsequence Examples

Sort type Usage of sortoder and sortsequence Description

Sort in ascending order

<ListOfContact startrownum="0" 
pagesize="100" recordcountneeded="true">
<Contact searchspec= "[ContactFirstName] 
LIKE  'Contact* ' ">
<ContactLastName sortorder="ASC"></
ContactLastName>
</Contact></ListOfContact>

Returns all contacts whose ContactFirstName value starts with "Contact" and ends with zero or more characters and sorts them by ContactLastName in ascending order

Sort in descending order

<ListOfContact startrownum="0" 
pagesize="100" recordcountneeded="true">
<Contact>
<ContactLastName sortorder="DESC">~LIKE 
'Contact*'</ContactLastName>
</Contact></ListOfContact>

Returns all contacts whose ContactLastName value starts with "Contact" and ends with zero or more characters and sorts them by ContactLastName in descending order

Sort More than One Field

<ListOfContact startrownum="0" 
pagesize="100" recordcountneeded="true">
<Contact searchspec= "[ContactFirstName] 
LIKE  'Contact* ' ">
<ContactLastName sortorder="DESC" 
sortsequence="1"></ContactLastName> 
<ContactFirstName sortorder="DESC" 
sortsequence="2"></ContactFirstName>
<ExternalSystemId sortorder="DESC" 
sortsequence="3"></ExternalSystemId>
</Contact></ListOfContact>

Returns all contacts whose ContactFirstName value starts with "Contact" and ends with zero or more characters and sorts them by ContactLastName in descending order and then by ContactFirstName in descending order and then by ExternalSystemId in descending order.