You need to sign in to do that
Don't have an account?
Pallav
how to use a data collection as a result of the query with another query using "In " ??
Hi All,
I am facing a issue with the my apex code trigger. I have the following queries:
it is giving me some invalid data binding error message.
1: - Compile Error: Incompatible element type Id for collection of SOBJECT:OpportunityLineItem at line 11 column 12 ------that means // options.add(i.OpportunityId); line.
2:- Compile Error: Invalid bind expression type of SOBJECT:OpportunityLineItem does not match domain of foreign key at line 15 column 116 ------ that means
OpportunityLineItem [] oppIds = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId In : options ];
here is the complete code of it......
if(trigger.isAfter)
{
if((trigger.isInsert)||(trigger.isUpdate))
{
try{
OpportunityLineItem [] OpIds = [Select OpportunityId from OpportunityLineItem where Id In : trigger.new];
List<OpportunityLineItem> options= new List<OpportunityLineItem>();
for(OpportunityLineItem i: OpIds)
{
// options.add(i.OpportunityId);
}
OpportunityLineItem [] oppIds = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId In : options ];// opportunity id bind exception
for (OpportunityLineItem c :oppIds)
{
OpportunityLineItem [] OLI = [Select PricebookEntry.Product2Id from OpportunityLineItem where Id=: c.Id];
Set<Id> Product2Ids = new Set<Id>();
for(OpportunityLineItem o:OLI)
{
Product2Ids.add(o.PricebookEntry.Product2Id);
}
Product2 [] P2 = [Select Welcome_Program__c from Product2 where Id in :Product2Ids];
for(Product2 pro2: P2)
{
if(pro2.Welcome_Program__c==true)
{
Opportunity opp=new Opportunity(Id=c.Id);
opp.Welcome_Program__c=true;
update opp;
}
}
}
}
catch(System.DmlException e)
{
System.assert(e.getDmlMessage(0).indexOf('Cannot Update opportunity') > -1);
}
}
}
Your little help can solve my issue.
Thanks in anticipation of your response.
thanks and regards
Pallav
I am facing a issue with the my apex code trigger. I have the following queries:
it is giving me some invalid data binding error message.
1: - Compile Error: Incompatible element type Id for collection of SOBJECT:OpportunityLineItem at line 11 column 12 ------that means // options.add(i.OpportunityId); line.
2:- Compile Error: Invalid bind expression type of SOBJECT:OpportunityLineItem does not match domain of foreign key at line 15 column 116 ------ that means
OpportunityLineItem [] oppIds = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId In : options ];
here is the complete code of it......
if(trigger.isAfter)
{
if((trigger.isInsert)||(trigger.isUpdate))
{
try{
OpportunityLineItem [] OpIds = [Select OpportunityId from OpportunityLineItem where Id In : trigger.new];
List<OpportunityLineItem> options= new List<OpportunityLineItem>();
for(OpportunityLineItem i: OpIds)
{
// options.add(i.OpportunityId);
}
OpportunityLineItem [] oppIds = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId In : options ];// opportunity id bind exception
for (OpportunityLineItem c :oppIds)
{
OpportunityLineItem [] OLI = [Select PricebookEntry.Product2Id from OpportunityLineItem where Id=: c.Id];
Set<Id> Product2Ids = new Set<Id>();
for(OpportunityLineItem o:OLI)
{
Product2Ids.add(o.PricebookEntry.Product2Id);
}
Product2 [] P2 = [Select Welcome_Program__c from Product2 where Id in :Product2Ids];
for(Product2 pro2: P2)
{
if(pro2.Welcome_Program__c==true)
{
Opportunity opp=new Opportunity(Id=c.Id);
opp.Welcome_Program__c=true;
update opp;
}
}
}
}
catch(System.DmlException e)
{
System.assert(e.getDmlMessage(0).indexOf('Cannot Update opportunity') > -1);
}
}
}
Your little help can solve my issue.
Thanks in anticipation of your response.
thanks and regards
Pallav
List options= new List();
should be
List options= new List();