You can use this API to check if a product exist in a category.

APISignature
productExistsInHierarchy

webService static Apttus_Config2.CPQAdminStruct.HierarchyResponseDO productExistsInHierarchy(Apttus_Config2.CPQAdminStruct.HierarchyRequestDO hierarchyRequestDO)



Request Parameter
NameTypeDescription
hierarchyRequestDOApttus_Config2.CPQAdminStruct.HierarchyRequestDOThe category request data object.
Request Parameter - Apttus_Config2.CPQAdminStruct.HierarchyRequestDO
NameTypeDescription
HierarchyDOsList<Apttus_Config2.CPQAdminStruct.HierarchyDO>The list of hierarchy data object



Data Object- Apttus_Config2.CPQAdminStruct.HierarchyDO
NameTypeDescription
ChildProductIdIdThe Id of child product.
ParentProductIdIdThe Id of the parent product.
Response Data Object- Apttus_Config2.CPQAdminStruct.HierarchyResponseDO
NameTypeDescription
IssuccessBooleanIndicates whether the product exists in the hierarchy or not.


Code Sample

The below sample code finds whether the child product is available in the hierarchy of its parent product.


public Boolean productExistsInHierarchy(String parentProductName, String childProductName) 
{
	Apttus_Config2.CPQAdminStruct.HierarchyDO hierDO = new Apttus_Config2.CPQAdminStruct.HierarchyDO();
	Apttus_Config2.CPQAdminStruct.HierarchyRequestDO hierRequest = null;
	Apttus_Config2.CPQAdminStruct.HierarchyResponseDO hierResponse = null;

	// get child, parent products, and option group
	Product2 parentProduct = [SELECT Id FROM Product2 WHERE Name = :parentProductName LIMIT 1];
	Product2 childProduct = [SELECT Id FROM Product2 WHERE Name = :childProductName LIMIT 1];
	
	hierRequest = new Apttus_Config2.CPQAdminStruct.HierarchyRequestDO();
	hierDO = new Apttus_Config2.CPQAdminStruct.HierarchyDO();
	hierDO.ParentProductId = parentProduct.Id;
	hierDO.ChildProductId = childProduct.Id;
	hierRequest.HierarchyDOs.add(hierDO);
	hierResponse = Apttus_Config2.CPQAdminWebService.productExistsInHierarchy(hierRequest);
	return hierResponse.Issuccess;
}
CODE