General X++ Development

How do I check if a record exists in X++?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I check if a record exists in X++?

SSunny Vasty75 reputation · answered Aug 13, 2026

Use firstOnly and check RecId.

X++
SalesTable salesTable;

select firstOnly RecId from salesTable
    where salesTable.SalesId == 'SO-000001';

if (salesTable.RecId)
{
    info('Record exists.');
}

If existence is all you care about, only select the field you actually need.