DataObject\ClassName::getByMyfieldname not working

As specified in https://pimcore.com/docs/5.x/Development_Documentation/Objects/Working_with_PHP_API.html, we can use
$result = DataObject\ClassName::getByMyfieldname($value, [int $limit, int $offset]);
to get an object/array of data objects which suits the value for that field.

My Code is following:
$product = Product::getByProductType("Base",1);
But it is unable to fetch the data objects and returns null every time.

$product = Product::getByProductType("Base");
In the case, it returns count 0 in the array.

Although I have more than 1000 data objects which satisfy the scenario.
Have anyone else faced this situation or in any way, help me out?

Thanks in advance.
Regards,
Akansh

Are the products published or not?
By default the function returns only published record.
You can change this behaviour by using “unpublished” parameter.
Here is example:
Product::getByProductType(“Base”,([‘limit’=>1, ‘unpublished’=>true]);

1 Like

Thanks Faiyaz.
But the data objects are already published.
Also, I have tried the same array as argument but got no results.
Could anyone lead me how to debug the getBy… function?

I would suggest you to use listing method like “$entries = new DataObject\Myclassname\Listing();”. Sometimes I also faced issues in getByMethod.

What is data type of ProductType field? Is it input or something else?

Yes it is input.
And it is working with Listing() but not with getByFieldName