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
RamkumarVTRRamkumarVTR 

SOQL Query in Apex Class

Please find below code is fetching the user's time off based on ownerid and user market. Some time we are getting the wrong datas like fetching the datas only based on the market. 

 

for(Working_Days__c wd : [select Id,User__c,Start_Date__c,End_Date__c,Expired__c,Market__c,RecordTypeId,Reason__c,Time__c,
M_AM__c,M_PM__c,Tu_AM__c,Tu_PM__c,W_AM__c,W_PM__c,
Th_AM__c,Th_PM__c,F_AM__c,F_PM__c,Sat_AM__c,Sat_PM__c,
Sun_AM__c,Sun_PM__c
from Working_Days__c
where Expired__c = false and (User__c = :ownerId or Market__c = :userMarket)  order by Time__c asc nulls last])

 

Expectation:

 

we are planning change the condition " where Expired__c = false and (User__c = :ownerId or (Market__c = :userMarket AND RecordTypeId= 'Company_Holdidays' "

 

But, we are facing problem in "  RecordTypeId= 'Company_Holdidays' " , please help me how to define and excute the same. 

Best Answer chosen by Admin (Salesforce Developers) 
gbu.varungbu.varun

YourName => Setup => Monitoring => Scheduled job.

Or you can dirctly type in left search box panel 

All Answers

gbu.varungbu.varun

Hi,

 

You are not passing record type id. You are passing record type name  RecordTypeId= 'Company_Holdidays' .

You have to find the recordtype id first and then make query for it.

RamkumarVTRRamkumarVTR

This is the part of apex class , so i could not able to pass the value directly...

gbu.varungbu.varun

Hi Ram,

 

You have to fine id from Recordtype as

 

RecordType r= [select id from RecordType where name=:'Company_Holdidays'' and SobjectType =:'Put Object api name here'];

 

and now you can make a query here:

 

Market__c = :userMarket AND RecordTypeId=:r.id

RamkumarVTRRamkumarVTR

Yes, I tried even the same. but i got error " Error: Compile Error: Schedulable class has jobs pending or in progress at line 12 column 8"

gbu.varungbu.varun

Either it is a batch or a batch is calling this class. You will have to delete all Scheduled job which are using this code. If you will not delete job you will not be able to update class or batch code.

RamkumarVTRRamkumarVTR

Please advise me , where i need to delet the batch file, please find below line 


gbu.varun wrote:

Either it is a batch or a batch is calling this class. You will have to delete all Scheduled job which are using this code. If you will not delete job you will not be able to update class or batch code.


 

In line 12: global class CyclePlanTOTSyncBatch implements Database.Batchable<sObject> 

gbu.varungbu.varun

YourName => Setup => Monitoring => Scheduled job.

Or you can dirctly type in left search box panel 

This was selected as the best answer