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

List is giving 0 in debug log from trigger even data exist

trigger OpportuntiyDelete on Opportunity (Before Delete) {
    list<SBQQ__Quote__c> qt = [select id from SBQQ__Quote__c where  SBQQ__Opportunity2__c = :trigger.oldmap.keyset()]; // Here it is always returning 0 even if it has data to return. 
   for(opportunity opp: trigger.old){

      opp.adderror('Opportunity record cannot be deleted' + ' '  + qt.size() + ' ' + + ' ' + cpqid  + ' ' + trigger.oldmap.keyset());


This list is returning 0 values even if data existing for opportunity. 

  list<SBQQ__Quote__c> qt = [select id from SBQQ__Quote__c where  SBQQ__Opportunity2__c = :trigger.oldmap.keyset()]; 

SBQQ__Quote__c is not a child object it has a lookup value of opportunity there is a no master child relationship. Please suggest me how to fix. 


Please check that SBQQ__Opportunity2__c is a lookup on Opportunity object, as this trigger works on Opportunity records.
Change your query to :
select id from SBQQ__Quote__c where  SBQQ__Opportunity2__c  IN: trigger.oldmap.keyset()

If tthis doesn't give you any record, the only reason list size is zero is because related records dont exist for given Id(s).
Copy Id of any Opportunity that you want to delete, run following command in Developer Console -> Query Editor ->
select id from SBQQ__Quote__c where  SBQQ__Opportunity2__c = 'copied Opportuntiy Id'
From here you will get to know whether given Opportunity has related records in SBQQ__Quote__cobject or not.

If this helps solve your problem, mark this as BEST ANWER
If the answer posted above has solved your issue, please mark it as best answer, or add details of any problems you faced after implementing suggestions