1

I am having a trigger which is using account name in where condition of SOQL query.Also,this trigger is on a custom object(not on account) which is having lookup to account.

for(Account acc: [Select FirstName,LastName,Territory_vod__c from Account where (Name In:accSet AND RecordType.Name='Press') limit 1]){
    //accSet is set having names and accSet stores the values from a field in custom object records which are available in trigger context.So I need to iterate over all account records without using name field in where condition

    if(acc.Territory_vod__c!=NULL &&acc.Territory_vod__c!='' ){
        for(String s: acc.Territory_vod__c.split('\\;')){
            if(s != Null && s != ''){
                primaryterr.add(s);
                string accname=acc.FirstName.toUpperCase() +' '+ acc.LastName.toUpperCase();
                if(accWithTerr.containsKey(accname)){
                    accWithTerr.get(accname).add(s);
                }
                else{
                    accWithTerr.put(accname, new List<String> {s} );
                }
            }
        }
    }
}

Business has asked to make this field encrypted,but it is throwing error

encrypted field 'Name' cannot be filtered in a query call

How can I resolve this without hitting governor limits? I can not use SOSL in triggers and there are over 60,000 account records with 'Press' record type.

What could be the workarounds?

8
  • Why encrypt the recordtype name? If it does need to be encrypted any workarounds would negate the encryption. However since you are limiting to the accounts on the accset you should be fine removing the filter and processing for the correct ones in a loop
    – Eric
    Commented Mar 2, 2017 at 6:40
  • I need to encrypt account name not recordtype name.And the above trigger is on a custom object having lookup to Account.(I should have mentioned this before).
    – devsfdc
    Commented Mar 2, 2017 at 6:44
  • And accSet stores the values from a field in custom object records which are available in trigger context.So I need to iterate over all account records without using name field in where condition.Will it be possible?
    – devsfdc
    Commented Mar 2, 2017 at 6:58
  • As this is a Standard Limit and you don't want to use SOSL either so you need to break the functionality in chunks and then need to query the data Commented Mar 2, 2017 at 7:08
  • 1
    Can you use the Id instead of name as the key for everything. Why Name?
    – Eric
    Commented Mar 2, 2017 at 13:19

0

You must log in to answer this question.

Browse other questions tagged .