You need to sign in to do that
Don't have an account?
Jerrad Schmittle
APEX Trigger Issue - HELP!
PLEASE HELP - I am trying to create a new Opportunity but I keep getting this error message:
Error: Invalid Data. Review all error messages below to correct your data. Apex trigger trg_Opportunity caused an unexpected exception, contact your administrator: trg_Opportunity: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.trg_Opportunity: line 15, column 1
...I was told that it has to do with an APEX trigger that I have set. I do not know how to go about turning off the APEX trigger or if there is something I can modify to allow the creation of manual Opportunities.
Please Advise.
Jerrad
Error: Invalid Data. Review all error messages below to correct your data. Apex trigger trg_Opportunity caused an unexpected exception, contact your administrator: trg_Opportunity: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.trg_Opportunity: line 15, column 1
...I was told that it has to do with an APEX trigger that I have set. I do not know how to go about turning off the APEX trigger or if there is something I can modify to allow the creation of manual Opportunities.
Please Advise.
Jerrad
1) Go to setup
2) Go to customize.
3) gor to opportunity and select Trigger
4) After it opens select "trg_Opportunity" trigger and edit it and deselect the Active checkbox.
Then try creating opportunity
If you can provide the code of trigger than we can find out the error and provide you the soluiton.
And
If you want to stop trigger to fire when you create data than you can do this by clcik on Setup --> in App Setup area -->Click on Develop-->click on Apex Trigger
Now you can see the list of Trigger click on edit link ot that trigger which is throwing error. I think the trigger name is trg_Opportunity this.
After click on edit link you can see there is check box Is Active uncheck this checkbox, then this trigger will not fire
IF it helps you than please mark it as a solution and ENJOY APEX
My guess without seeing the code is that you're requerying the records in your trigger when you don't need to and/or you're querying all records from an object when you don't need to.
trigger trg_Opportunity on Opportunity (before update, before insert) {
Map<string, Id> oppAccountNameMap = new Map<string, Id>();
Map<Id, Id> oppAccountIdMap = new Map<Id,Id>();
// Get the id of Account : 'Opportunities Without Accounts'
List<Account> accList = new List<Account>([select Id from account where name = 'Opportunities Without Accounts']);
//Create Map of AccountName - OppId
for(Opportunity oppObj : Trigger.New)
{
oppAccountNameMap.put(oppObj.BC_Account_Lookup__c, oppObj.Id);
}
//Create Map of OppId - AccId
for(Account acc : [select Id, Name from account where Name in :oppAccountNameMap.keyset()])
{
for(string accName : oppAccountNameMap.keyset())
{
if(acc.Name == accName)
{
oppAccountIdMap.put(oppAccountNameMap.get(accName), acc.Id);
}
}
}
//Set the correct AccountId for each Opp and set 'Opportunities Without Accounts' for other Opportunities
for(Opportunity oppObj : Trigger.New)
{
if(oppAccountIdMap.keyset().contains(oppObj.Id))
oppObj.AccountId = oppAccountIdMap.get(oppObj.Id);
else
{
if(accList.size() == 1)
oppObj.AccountId = accList[0].Id;
else
{
//If there is no 'Opportunities Without Accounts' account then throw error.
oppObj.AccountId.AddError('No Account to assign');
}
}
}
}
I don't want to disable the trigger entirely, is there something that can be changed that will not prevent me from creating a manual Opportunity?
Jerrad