You can use this API to remove a product from a category.

APISignature
removeProductFromHierarchy

webService static Apttus_Config2.CPQAdminStruct.HierarchyResponseDO removeProductFromHierarchy(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 removal of the product from the hierarchy.


Code Sample

The below sample code enables you to remove the products from their relevant category.


/**
 * The below code removes the products from category. Invoke below method by passing parent and child product names.
 * Remove a child product from a hierarchy of a parent product.
 * The input request contains the Child Product Id and the Parent Product Id.
 * In case a list of products is passed, this will be an all-or-none scenario stored in 
 * the single Boolean return value.
 */

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

	// STEP 1 - Retrieve data
	// 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];

	// STEP 2 - Remove child from hierarchy
	// build request object		
	hierDO = new Apttus_Config2.CPQAdminStruct.HierarchyDO();
	hierDO.ParentProductId = parentProduct.Id;
	hierDO.ChildProductId = childProduct.Id;
	hierDO.ParentOptionGroupId = null;
	hierDO.ChildOptionGroupId = null;
	// add hierarchy DO to request
	hierRequest.HierarchyDOs.add(hierDO);

	// send request for removal and save response
	removeResponse = Apttus_Config2.CPQAdminWebService.removeProductFromHierarchy(hierRequest);
	return removeResponse.Issuccess;
}
CODE