You need to sign in to do that
Don't have an account?
Sepur Anil
I need LastActivity < Last_N_Days:90 Soql Query can any one help me.
I have Standard Object and Custom Object
Standard Object fields are Id, LastactivityDate. Object name is Leads
Custom Object fields are Id, Lead__c. Object Name Email_Lead_Sync__c
I need LastActivity < Last_N_Days:90 Soql Query can any one help me.
Standard Object fields are Id, LastactivityDate. Object name is Leads
Custom Object fields are Id, Lead__c. Object Name Email_Lead_Sync__c
I need LastActivity < Last_N_Days:90 Soql Query can any one help me.
If you want to do SOQL query using LAST_N_DAYS:90 functinality in a simple way then you can write this:
//It will return all the list of leads having LastActivityDate < LAST_N_DAYS:90
List<Lead> leadList = [Select Id,LastActivityDate from Lead WHERE LastActivityDate < LAST_N_DAYS:90 Limit 10000];
And if you want to use custom Object(Email_Lead_Sync__c) and standared object(Lead). If Custom object(Email_Lead_Sync__c) have the lookup(relation) with Lead(standared object) in the Lead__c field then you can try this:
List<Lead> leadList = [Select Id,LastActivityDate from Lead WHERE LastActivityDate < LAST_N_DAYS:90 Limit 10000];
if(leadList.size()>0) {
Set<Id> leadIdSet = new Set<Id>();
for (Lead temp : leadList) {
leadIdSet.add(temp.Id);
}
//'emailLeadList'- contains all the list of 'email Lead List' having the relation with Lead and LastActivityDate < LAST_N_DAYS:90
List<Email_Lead_Sync__c> emailLeadList = new List<Email_Lead_Sync__c>();
emailLeadList = [SELECT Id, Lead__c FROM Email_Lead_Sync__c WHERE Lead__c IN: leadIdSet Limit 10000];
}
If your requirement is anything else then please provide me whole requirement.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
I hope this query will solve your problem.
Thanks
This is the first query
Select Id, Name, lastActivityDate from Lead where IsConverted = False and LastActivityDate < LAST_90_DAYS
You will get the list of LeadIds from the above query.
You have to pass that LeadIds in below query [where Lead__c in ()].
This is the second qry
Select lead__c,lastmodifieddate,createddate from Email_Lead_Sync__c where Lead__c in () and lastmodifieddate = LAST_90_DAYS
Now you will get the list of LeadIds from the above query
Final list of LeadIds [for update] = First query LeadIds - Second query LeadsId.
For this I need batch class
If you want to do SOQL query using LAST_N_DAYS:90 functinality in a simple way then you can write this:
//It will return all the list of leads having LastActivityDate < LAST_N_DAYS:90
List<Lead> leadList = [Select Id,LastActivityDate from Lead WHERE LastActivityDate < LAST_N_DAYS:90 Limit 10000];
And if you want to use custom Object(Email_Lead_Sync__c) and standared object(Lead). If Custom object(Email_Lead_Sync__c) have the lookup(relation) with Lead(standared object) in the Lead__c field then you can try this:
List<Lead> leadList = [Select Id,LastActivityDate from Lead WHERE LastActivityDate < LAST_N_DAYS:90 Limit 10000];
if(leadList.size()>0) {
Set<Id> leadIdSet = new Set<Id>();
for (Lead temp : leadList) {
leadIdSet.add(temp.Id);
}
//'emailLeadList'- contains all the list of 'email Lead List' having the relation with Lead and LastActivityDate < LAST_N_DAYS:90
List<Email_Lead_Sync__c> emailLeadList = new List<Email_Lead_Sync__c>();
emailLeadList = [SELECT Id, Lead__c FROM Email_Lead_Sync__c WHERE Lead__c IN: leadIdSet Limit 10000];
}
If your requirement is anything else then please provide me whole requirement.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
and
Status to remarketing