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
MaheemSamMaheemSam 

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

Hi, 
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() + ' ' + opp.id + ' ' + 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. 

Thanks
Sudhir

 
mritzimritzi
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
mritzimritzi
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