You need to sign in to do that
Don't have an account?
swapna muthiyalu
i have the following code
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();
list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ]
now i want to check if mEmpId and hEmpId are blank and if it is blank i have to run this query? how to check the set is empty?
set<string>hEmpId = new set<string>();
list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ]
now i want to check if mEmpId and hEmpId are blank and if it is blank i have to run this query? how to check the set is empty?
* // run if mEmpId and hEmpId both are NOT blank
// run if mEmpId and hEmpId both are blank
Thanks, let us know if it helps you
All Answers
The method is isEmpty() which returns true if the Set is not empty and false otherwise. To see this and other Set Class's methods, take a look at this:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_set.htm
* // run if mEmpId and hEmpId both are NOT blank
// run if mEmpId and hEmpId both are blank
Thanks, let us know if it helps you
set<string>mEmpId = new set<string>();
set<string>hEmpId = new set<string>();
if (!mEmpId. isEmpty() && !hEmpid.isEmpty())
list<contact>listcon = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexm__c = ‘yes’) or (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’)
will this work?
will this work?
if (!mEmpId. isEmpty() && !hEmpid.isEmpty())
yes you can use the both the Size() and IsEmpty(). Mostly used is Size().
Size() = Returns the number of elements in the set . So by using Size() > 0 we can check there is Element is presented or not.
IsEmpty() = Returns true if the set has zero elements.
Always Use the Salesforce Provided Technical document that will be ver usefull!!!
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_set.htm
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
i want the check all these conditions now, how to convert this query into dy.namic query. Please suggest
if (mEmpId .size() == 0){
list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : hEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];
} else if(hEmpId.size() == 0){
list<Contact> mgrHrRecs = [select id, empid__c,AccountId, Type__c from contact where (empid__c IN : mEmpId and AccountId IN :accountids and indexh__c = ‘yes’) ];
(mEmpId.size() >
0
&& hEmpId.size() >
0)