To implement this in REST API, you need two calls.
The first call to determine if PrimaryWhoId
is available
Call /services/data/v45.0/sobjects/ActivityHistory/describe
and check response fields
attributes and check if PrimaryWhoId
is present in the list.
Then if PrimaryWhoId
is present in the fields map, execute query
SELECT
(SELECT Id, IsTask, ActivityDate, ActivitySubtype, Subject, Owner.Name,PrimaryWhoId,WhatId,PrimaryWho.Name, What.Name from ActivityHistories
ORDER BY ActivityDate DESC NULLS LAST, LastModifiedDate DESC LIMIT #{limit})
FROM Account where id =
otherwise execute
SELECT
(SELECT Id, IsTask, ActivityDate, ActivitySubtype, Subject, Owner.Name,WhoId,WhatId,Who.Name, What.Name from ActivityHistories
ORDER BY ActivityDate DESC NULLS LAST, LastModifiedDate DESC LIMIT #{limit})
FROM Account where id =
Example of response
{
"actionOverrides" : [ ],
"activateable" : false,
"childRelationships" : [ ],
"compactLayoutable" : false,
"createable" : false,
"custom" : false,
"customSetting" : false,
"deletable" : false,
"deprecatedAndHidden" : false,
"feedEnabled" : false,
"fields" : [
{
"aggregatable" : true,
"aiPredictionField" : false,
"autoNumber" : false,
"byteLength" : 18,
"calculated" : false,
"calculatedFormula" : null,
"cascadeDelete" : false,
"caseSensitive" : false,
"compoundFieldName" : null,
"controllerName" : null,
"createable" : false,
"custom" : false,
"defaultValue" : null,
"defaultValueFormula" : null,
"defaultedOnCreate" : false,
"dependentPicklist" : false,
"deprecatedAndHidden" : false,
"digits" : 0,
"displayLocationInDecimal" : false,
"encrypted" : false,
"externalId" : false,
"extraTypeInfo" : null,
"filterable" : true,
"filteredLookupInfo" : null,
"formulaTreatNullNumberAsZero" : false,
"groupable" : true,
"highScaleNumber" : false,
"htmlFormatted" : false,
"idLookup" : false,
"inlineHelpText" : null,
"label" : "Name ID",
"length" : 18,
"mask" : null,
"maskType" : null,
"name" : "WhoId",
"nameField" : false,
"namePointing" : true,
"nillable" : true,
"permissionable" : false,
"picklistValues" : [ ],
"polymorphicForeignKey" : true,
"precision" : 0,
"queryByDistance" : false,
"referenceTargetField" : null,
"referenceTo" : [ "Contact", "Lead" ],
"relationshipName" : "Who",
"relationshipOrder" : null,
"restrictedDelete" : false,
"restrictedPicklist" : false,
"scale" : 0,
"searchPrefilterable" : false,
"soapType" : "tns:ID",
"sortable" : true,
"type" : "reference",
"unique" : false,
"updateable" : false,
"writeRequiresMasterRead" : false
},
You need to check if there is a field with name attribute PrimaryWhoId
.