You need to sign in to do that
Don't have an account?
chandrashekar Jangiti
Hi Folks..I need here one solution for below code for best practices we need to add constant variable for Recordtype names how we can add?
code is:
List<Id> rectypeId=new List<Id>();
for(RecordType r:[Select Id,Name from RecordType where sObjectType ='Contact' AND DeveloperName IN('Contact')]){
rectypeId.add(r.Id);
}
Here how we can add constant variable for "DeveloperName IN('Contact')".
thanks,
Chandu
List<Id> rectypeId=new List<Id>();
for(RecordType r:[Select Id,Name from RecordType where sObjectType ='Contact' AND DeveloperName IN('Contact')]){
rectypeId.add(r.Id);
}
Here how we can add constant variable for "DeveloperName IN('Contact')".
thanks,
Chandu
Incase you want to add filter in the query and add a variable, then you can write your query in the form of String and then concatenate.
Sample Code:
Thanks,
Ashish Singh.
String query = 'Select Id,Name from RecordType where sObjectType =\'Contact\' ';
String var = ' AND DeveloperName IN (\'Contact\')';
String var1 = ' AND DeveloperName IN (\'test1\')';
query = query + var+var1; --------------------------------------------------------------------> like this or how it is?
List<RecordType> rt = Database.query(query);
System.debug('RT Size =>'+rt.size());
for(RecordType r:rt){
System.debug('RT =>'+r);
}
thanks,
Chandu
Why don't you just modify your var. Just add all in condition in it.
You can refer to the Dynamic SOQL (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm) for more information.
Thanks,
Ashish Singh