function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Karunat1Karunat1 

Delete Records

I want to delete records from PageBlockTable via Remote Action?
Sohan Raj GuptaSohan Raj Gupta
Hi Karuna,

You can also delete records by following code:
 
<apex:pageBlockTable value="{!accts}" var="a" id="table">
                <apex:facet name="footer">
                         <apex:commandLink value="Add Item" action="{!addRow}" rerender="table,error"/>
                                          </apex:facet>                
                <apex:column headerValue="Object One Name">
                    <apex:inputField value="{!a.obj_1__c}"/>
                </apex:column>
                <apex:column headerValue="Number">
                    <apex:inputField value="{!a.Number1__c}"/>
                </apex:column>
                </apex:pageBlockTable>

       <apex:pageBlockTable value="{!accts}" var="a" id="table1">
            <apex:facet name="footer">
                          <apex:commandLink value="Remove Item" action="{!RemoveRow}" rerender="table1,error"/>
                </apex:facet>

            </apex:pageBlockTable>
 
public with sharing class ClsBook {
  
    public List<Book__c> accts {get; set;}
    public integer counter=1;   
   
    Book__c record;
    Book2__c record1 = new Book2__c();
   
    public ClsBook(ApexPages.StandardController controller) {
        record = (Book__c)controller.getRecord();
        record.Test_Name__c= ApexPages.currentPage().getParameters().get('oppId');   
        record.author__c='JAPAN/USA';
        record.Name=record.Test_Name__r.Test_1__c;
        record.Start_Date__c=DateTime.Now().Date();
        record.End_Date__c=DateTime.Now().Date().AddMonths(10);
        accts = new List<Book__c>();
        accts.add(new Book__c());   
    }
    public void addrow(){
        accts.add(new Book__c());
        counter++;
        system.debug(counter);
    }  
    public void RemoveRow(){
        system.debug('Remove Black');
       
        Integer i = accts.size();
        accts.remove(i-1);
        system.debug(i);

    } 
    public void Save1(){
        try{
            insert record;
            //PageReference pr=new PageReference('/'+record.id);           
            for(integer i=0;i<counter;i++){
                record1.Number__c = record.Number1__c;
                record1.Name = record.Number1__c;
                record1.obj_1__c= record.obj_1__c;
                record1.Book__c=record.id;                           
                insert record1;
            }
        }
        catch(exception e){
            System.debug(e);
        } 
    }  
    public PageReference save(){
        insert record;
        PageReference pr=new PageReference('/'+record.id);           
        record1.Number__c = record.Number1__c;
            record1.Name = record.Number1__c;
            record1.obj_1__c= record.obj_1__c;
            record1.Book__c=record.id;               
            insert record1;
        
         return pr;
    }         
}

If you still want to delete record by RemoteAction, let me know. I will share code according that.

Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 
Karunat1Karunat1
but I want to delete record by RemoteAction