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
Akhil Katkam 5Akhil Katkam 5 

How can i filter opportunity related recent ids from RecentlyViewed query

Hi Developer Community , 

i am working on a task (i have createda custom lookup field component ) 

in my apex class i have taken records based on recently viewed 
 
for(RecentlyViewed recent : [SELECT Id,Name FROM RecentlyViewed WHERE Type =:ObjectName]) {
            recentIds.add(recent.Id);
        }
this is the code i kept in apex class , but i need the records based on opportunity object 

actually i kept this component in opportunity record page , so i need to get particular opportunity related recoprds only 

i tried keeping where opportunity__c:rec 

but i am getting error , how to take particular opportunity related record ids 
please help me with the ideas and solution

Thanks in Advacnce


 
Maharajan CMaharajan C
Hi Akhil,

You can directly use the Opportunity object name in the type right or you are looking for something else.
 
for(RecentlyViewed recent : [SELECT Id,Name FROM RecentlyViewed WHERE Type ='Opportunity']) {
            recentIds.add(recent.Id);
        }

Thanks,
Maharajan.C
Akhil Katkam 5Akhil Katkam 5
hi Maharajan c , thanks for the reply , but my requirement is , i want to fetch records of competition  where oppottunity:=rec

i will show u an example:         list<competition__c> comp= [select id,Name from competition__c where Opportunity__c =:rec];
here i am fetching competition records with respect to opportunity , in the same way i want to fetch for recently viewed records