You need to sign in to do that
Don't have an account?
Swaroopa Akula 2
Getting below error while I am inserting Opportunities using dataloader.ERROR: dlrs_OpportunityTrigger: execution of AfterInsertcaused by: System.QueryException: List has more than 1 row for assignment to SObject()
Getting below error while I am inserting Opportunities using dataloader.
ERROR: dlrs_OpportunityTrigger: execution of AfterInsertcaused by: System.QueryException: List has more than 1 row for assignment to SObject()
Below is the trigger code:
/**
* Auto Generated and Deployed by the Declarative Lookup Rollup Summaries Tool package (dlrs)
**/
trigger dlrs_OpportunityTrigger on Opportunity
(before delete, before insert, before update, after delete, after insert, after undelete, after update){
{
dlrs.RollupService.triggerHandler(Opportunity.SObjectType);
}
if(trigger.isafter&& trigger.isInsert){
Set<id> oId = new set<id>();
for(Opportunity opp : trigger.new){
oId.add(opp.Id);
}
Opportunity opp = [select Id ,NRR_value__c ,CurrencyIsoCode,RecordTypeId,recordtype.name from Opportunity where ID =: oId];
system.debug('opp************'+opp);
PriceBookEntry p = [SELECT Id, Product2Id, Product2.Id, Product2.Name, CurrencyIsoCode FROM PriceBookEntry WHERE
Product2Id='01t0J00000IDOpDQAX' and CurrencyIsoCode =: opp.CurrencyIsoCode and Pricebook2Id = '01s0J000002SCKDQA4' LIMIT 1];
system.debug('p***************'+p);
string recordtypename = Schema.SObjectType.Opportunity.getRecordTypeInfosById().get(opp.recordtypeid).getname();
system.debug(' recordtypename*************'+recordtypename);
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
for(Opportunity op : trigger.new){
if(opp.RecordType.Name == 'Services Record Type'){
OpportunityLineItem oli = new OpportunityLineItem();
oli.OpportunityId = opp.Id;
oli.Quantity = 1;
oli.PricebookEntryId = p.Id;
//oli.name = opp.name;
oli.UnitPrice = opp.NRR_value__c;
oliList.add(oli);
system.debug('oliList------------'+oliList);
}
}
insert oliList;
}
}
Pls let me know what is the issue
ERROR: dlrs_OpportunityTrigger: execution of AfterInsertcaused by: System.QueryException: List has more than 1 row for assignment to SObject()
Below is the trigger code:
/**
* Auto Generated and Deployed by the Declarative Lookup Rollup Summaries Tool package (dlrs)
**/
trigger dlrs_OpportunityTrigger on Opportunity
(before delete, before insert, before update, after delete, after insert, after undelete, after update){
{
dlrs.RollupService.triggerHandler(Opportunity.SObjectType);
}
if(trigger.isafter&& trigger.isInsert){
Set<id> oId = new set<id>();
for(Opportunity opp : trigger.new){
oId.add(opp.Id);
}
Opportunity opp = [select Id ,NRR_value__c ,CurrencyIsoCode,RecordTypeId,recordtype.name from Opportunity where ID =: oId];
system.debug('opp************'+opp);
PriceBookEntry p = [SELECT Id, Product2Id, Product2.Id, Product2.Name, CurrencyIsoCode FROM PriceBookEntry WHERE
Product2Id='01t0J00000IDOpDQAX' and CurrencyIsoCode =: opp.CurrencyIsoCode and Pricebook2Id = '01s0J000002SCKDQA4' LIMIT 1];
system.debug('p***************'+p);
string recordtypename = Schema.SObjectType.Opportunity.getRecordTypeInfosById().get(opp.recordtypeid).getname();
system.debug(' recordtypename*************'+recordtypename);
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
for(Opportunity op : trigger.new){
if(opp.RecordType.Name == 'Services Record Type'){
OpportunityLineItem oli = new OpportunityLineItem();
oli.OpportunityId = opp.Id;
oli.Quantity = 1;
oli.PricebookEntryId = p.Id;
//oli.name = opp.name;
oli.UnitPrice = opp.NRR_value__c;
oliList.add(oli);
system.debug('oliList------------'+oliList);
}
}
insert oliList;
}
}
Pls let me know what is the issue
System.QueryException: List has more than 1 row for assignment to SObject()
You are doing a query which is returning a List which you are trying to assign to a single object.
Your issue is here:
Any SELECT statement will produce a List
So adjust using one of the following options:
Use LIMIT 1 or pass it back to a list and then grab the first record to be used
regards
Andrew