function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PavanReddyPavanReddy 

How to find no of records in a object using lookup relations?

How to find no of records in  a object using lookup relations?

Yoganand GadekarYoganand Gadekar

Hi,

 

You can store the id of the look up in a ID varaibale and then get the type of the object

, Once you have type of the object you can get the count

 

ID objectId = your LOOK up id;

string ObjectString=string.valueof(objectId .getSObjectType());

String QueryString = 'select count() from' + ObjectString;

Integer Recordcount = Database.query(QueryString);

 

thanks,

 

 

AnushaAnusha

just open Developer Console and rund this query

 

Integer iLookupCount = [select count() from <childObject> where <lookup_Field> != null];

system.debug(' # of lookup relation records are :  '+iLookupCount);

Vinita_SFDCVinita_SFDC

Hello Pawan,

 

If an object is having lookup relationship then each record will be having the lookup field. Now if the lookup field is blank for any record then you can query over the object with the condition where test_lookup_field not equals to blank.