You need to sign in to do that
Don't have an account?
suji srinivasan
Hi , i have to query a prospectaccount without opportunity and task for last two years
I queried Tasks
SELECT accountid FROM Task WHERE What.Type = 'Account 'AND CreatedDate = LAST_N_MONTHS:24
I queried Account and Opportunity
SELECT Id, Name FROM account WHERE Rating = 'Prospect 'AND Id NOT IN (SELECT accountid FROM Opportunity WHERE CreatedDate = LAST_N_MONTHS:24)
how to connect this withmy Account and opportunity.
Thanksin Advance
SELECT accountid FROM Task WHERE What.Type = 'Account 'AND CreatedDate = LAST_N_MONTHS:24
I queried Account and Opportunity
SELECT Id, Name FROM account WHERE Rating = 'Prospect 'AND Id NOT IN (SELECT accountid FROM Opportunity WHERE CreatedDate = LAST_N_MONTHS:24)
how to connect this withmy Account and opportunity.
Thanksin Advance
You can store the all accountid's in a set collection and then run query on account excluding the ids which are in the set.
Set<Account> accIds = new Set<Account>();
for(Task thisTsk : [SELECT accountid FROM Task WHERE What.Type = 'Account 'AND CreatedDate = LAST_N_MONTHS:24]){
accIds.add(thisTsk.accountId);
}
for(Opportunity thisOpp : [(SELECT accountid FROM Opportunity WHERE CreatedDate = LAST_N_MONTHS:24]){
accIds.add(thisOpp.accountId);
}
List<Account> accList = [SELECT Id, Name FROM account WHERE Rating = 'Prospect 'AND Id NOT IN: accIds];
This list will have your values.
Thanks and Regards,
Tushar Mathur
All Answers
You can store the all accountid's in a set collection and then run query on account excluding the ids which are in the set.
Set<Account> accIds = new Set<Account>();
for(Task thisTsk : [SELECT accountid FROM Task WHERE What.Type = 'Account 'AND CreatedDate = LAST_N_MONTHS:24]){
}
You can store the all accountid's in a set collection and then run query on account excluding the ids which are in the set.
Set<Account> accIds = new Set<Account>();
for(Task thisTsk : [SELECT accountid FROM Task WHERE What.Type = 'Account 'AND CreatedDate = LAST_N_MONTHS:24]){
accIds.add(thisTsk.accountId);
}
for(Opportunity thisOpp : [(SELECT accountid FROM Opportunity WHERE CreatedDate = LAST_N_MONTHS:24]){
accIds.add(thisOpp.accountId);
}
List<Account> accList = [SELECT Id, Name FROM account WHERE Rating = 'Prospect 'AND Id NOT IN: accIds];
This list will have your values.
Thanks and Regards,
Tushar Mathur