i am suddenly getting the following error in apex trigger :
"System.LimitException: Too many query rows: 50001"
Here is my apex trigger code :
trigger SetAmountfromOTTtoSFDC on Opportunity (Before Insert, Before Update) {
Map <string, Id> AccountTextIdMap = new Map<String,Id>();
Map <string, Id> ContactTextIdMap = new Map<String,Id>();
if(Trigger.IsInsert || Trigger.IsUpdate){
List<Account> AccList = [select Id, Name, AccountId__c from Account];
for(Account ac : AccList){
AccountTextIdMap.put(ac.AccountID__c, ac.id);
}
List<Contact> ConList = [select Id, Contact_ID__c from Contact];
for(Contact con : ConList){
ContactTextIdMap.put(con.Contact_ID__c, con.id);
}
for(Opportunity op : Trigger.New){
if(op.AdrAccountSearchKey__c != Null && op.AccountId == Null){
op.AccountId = AccountTextIdMap.get(op.AdrAccountSearchKey__c);
}
if(op.AdrContactSearchKey__c != Null && op.Contact__c == Null){
op.Contact__c = ContactTextIdMap.get(op.AdrContactSearchKey__c);
}
}
}
I am using this trigger to set up the records which all are coming from other system using synchronization
i think Batch is very useful to this case but i am not sure how to do it, can somebody help me out
Thanks