You need to sign in to do that
Don't have an account?
LiorG
Need to delete Products from Opportunity
I have an Opportunity Controller that deletes each product on the Opportunity saved. Below is the snippet of code that does this. Olis comes out blank from this query. What am I doing wrong?
List<OpportunityLineItem> olis = [Select Id, pricebookentryid From OpportunityLineItem Where Id = :ApexPages.currentPage().getParameters().get('id')]; for (OpportunityLineItem oli : olis) { delete oli;
}
I think you are trying to delete OpporunityLineItems from Opportunity layout. If so then try below code
If you are using any custom functionality, make sure you have id parameter in the query string which has opportunity Id in it.
Regards,
Lakshman
All Answers
1) Make sure that
is returning you the Id of OpportunityLineItem and NOT of Opportunity because you are querying the data from OpportunityLineItem
2) Another problem which you may face with this code is DML operation limit as you have written delete in for loop. So I don't think there is a need of for loop, you can simply delete olis if it's size is > 0
Thanks
Ankit Arora
Blog | Facebook | Blog Page
I think you are trying to delete OpporunityLineItems from Opportunity layout. If so then try below code
If you are using any custom functionality, make sure you have id parameter in the query string which has opportunity Id in it.
Regards,
Lakshman
Hi,
I think your query should be like below because you are passing the Opportunity ID instead of OpportunityLineItem id :
List<OpportunityLineItem> olis = [Select Id, pricebookentryid From OpportunityLineItem Where OpportunityId = :ApexPages.currentPage().getParameters().get('id')];
if(olis.size()>0)
delete olis;
Try to avoid and SOQL or DML operation inside the loop because it will hit the governors limit
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. .
Thanks, got it.