You need to sign in to do that
Don't have an account?
Nervosa
Deleting an item by ID on a VF page
Greetings to everyone!
On my VF i have a commandlink and it looks like this:
<apex:commandLink value="Delete" action="{!del}"> <apex:param name="idtodel" value={!pitem.merchandise.id}"/> </apex:commandLink>
In my Apex controller i want to implement deletion like this:
public PageReference del() { Id IdToDel=System.currentPageReference().getParameters().get('id'); Item__c ItemToDel = [SELECT all FROM Item__c WHERE id = IdToDel]; PageReference curPage = ApexPages.currentPage(); curPage.getParameters().put('success','true'); curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id')); curPage.setRedirect(true); return curPage; }
and i get an error "unexpected token: 'IdToDel' at line 7 column 40"
Hi Nervosa,
Use colon (:) before your varaible,
Item__c ItemToDel = [SELECT all
FROM Item__c
WHERE id = :IdToDel];
use colone (:)IdToDel
Please mark this post as solved, if it helps you
Regards,
Bharathi
Salesforce For All
All Answers
My VF page:
My Apex controller:
Hi Nervosa,
Use colon (:) before your varaible,
Item__c ItemToDel = [SELECT all
FROM Item__c
WHERE id = :IdToDel];
use colone (:)IdToDel
Please mark this post as solved, if it helps you
Regards,
Bharathi
Salesforce For All
Hi Nervosa,
I'm just adding one more point to Bharathi
This line should be changed to the followed as , You taken the param name in the page as " idtodel "
THANK YOU VERY VERY MUCH =)
But there is one more little question i can't find answer to. How can i select ALL fields in a query? In SQL it's simply a ' * '. And how can i do it here?
Hi Nervosa,
In SOQL, we cant use ' * ' to query all fields like SQL
1. Specify all the fields manually in the query
2. use fieldset concept and add all fields to fieldset
The usage of fieldsets for querying all the fields goes as followed..!
Thanks for answers.
Not to create another thread i ask here again.
Now my controller looks this way:
And my VF page:
But when i click any of commandButtons to perfom deletion i get an error: "System.QueryException: List has no rows for assignment to SObject
"
Did you check whether " IdToDel " value is populated with value being sent from the page..?
Finally i've found the solution. The only thing i needed to do is to put CommandLink instead of CommandButton.
Now my VF page is:
And my Apex controller: