Reputation: 512
I need to pass id field value to apex class to delete that row by using command button.
Class:
public class search_delete
{
public string id {get;set;}
public list<account> acc{get;set;}
public search_delete()
{
acc = new list<account>();
acc = [SELECT id,name,phone,industry from account];
}
public void delete_record()
{
acc = [SELECT name,phone,industry from account where id = :id];
delete acc;
}
}
VP:
<apex:page controller="search_delete" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Industry}"/>
<apex:column >
<apex:commandButton value="Delete" Action="{!delete_record}">
<apex:param name="accId" value="{!a.id}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Now i need to pass id value to apex class from Vp page by the click of delete button. My Output
Upvotes: 0
Views: 2754
Reputation: 11
use the assignto property of apex command button.
<apex:page controller="search_delete" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Industry}"/>
<apex:column >
<apex:commandButton value="Delete" Action="{!delete_record}">
<apex:param name="accId" value="{!a.id}" assignto="{!idchosen}/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
public class search_delete
{
public string id {get;set;}
public string idchosen {get;set;}
public list<account> acc{get;set;}
public search_delete()
{
acc = new list<account>();
acc = [SELECT id,name,phone,industry from account];
}
public void delete_record()
{
acc = [SELECT name,phone,industry from account where id = :idchosen];
delete acc;
}
}
Upvotes: 1