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
veeru417veeru417 

Problem with saving pagereference method pls can any one help me pls

Hello every one i want to implement a fucntionality like shoping cart.In this there is a form to fill details,after filling we need to press add ,when we press add the details in form should added to  pageblock table one by one but the records are not commited until we press save button.

In this i have completed adding to pageblock table but facing the problem when saving records can any one help me pls

i am attching my code too

visual force code :

<apex:page standardController="Test_Case_Log__c" extensions="TestClass"  >
    <apex:form id="form">
        <apex:pageMessages />
        <apex:pageBlock >
           <apex:pageBlockButtons >   
                <apex:commandButton value="save" action="{!save1}"  rerender="pbtable"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Information" id="psi" >
                <apex:inputField value="{!testlog.Developer__c}" />
                <apex:inputfield value="{!testlog.name}"  />
                <apex:inputField value="{!testlog.Priority__c}" />
                <apex:inputField value="{!testlog.Test_Cases__c}" />
                <apex:inputField value="{!testlog.Tester__c}" />
                <apex:inputField value="{!testlog.Test_Scenario__c}"  />
            </apex:pageBlockSection>   
            <apex:pageBlockSection title="Description" id="psd">
                <apex:inputField value="{!testlog.Expected_Result__c}" />
                <apex:inputField value="{!testlog.Test_Case_Notes__c}" />
            </apex:pageBlockSection>        
            <apex:pageBlockTable value="{!testlog1}" var="a" id="pbtable"  >
                <apex:column value="{!a.Priority__c}" headerValue="Priority"/>
                <apex:column value="{!a.Developer__c}" headerValue="Developer"/>
                <apex:column value="{!a.Test_Cases__c}" headerValue="Expected_Result"/>
                <apex:column value="{!a.Test_Scenario__c}" headerValue="testscenario"/>
            </apex:pageBlockTable>
            <apex:commandButton action="{!add}" value="add" rerender="form"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

public with sharing class TestClass {
    public TestClass(ApexPages.StandardController controller) {
    testlog = (Test_Case_Log__c)Controller.getRecord();
        }
   
   public list<Test_Case_Log__c> tdt = new list<Test_Case_Log__c>();
   public  list<Test_Case_Log__c> gettestlog1(){
        return tdt;
   }  
   public Test_Case_Log__c testlog{set;get;}
    
    
    public void add(){
        tdt.add(testlog);
        testlog =new Test_Case_Log__c();
       
        
    }
    public pagereference save1(){
        
       
        insert tdt;
      
       PageReference pageRef = new PageReference('/apex/testpage');
        return pageRef;
    }
}

 Thank you

Best Answer chosen by Admin (Salesforce Developers) 
veeru417veeru417

yes i have solved the issue ,i have added 

<apex:commandButton value="save" action="{!save1}"  immediate="true"/>

 

so it will skip the validation.

Thanks for your helping behaviour,i have one more issue ,

i need to delete the individual record on the table can you help me in the above form.

i.e i need to have individual delete button for every row n when we press the button it need to delete the particular row.

All Answers

kiranmutturukiranmutturu

whats the problem that you are facing?

veeru417veeru417

when i am saving all the records on table  it is  throwing validation error,form is having one master detail relation ship fild the save method is trying to save the empty form ,so it is giving validation error

 

kiranmutturukiranmutturu

r u giving the master detail value in the UI?

veeru417veeru417

yes i have solved the issue ,i have added 

<apex:commandButton value="save" action="{!save1}"  immediate="true"/>

 

so it will skip the validation.

Thanks for your helping behaviour,i have one more issue ,

i need to delete the individual record on the table can you help me in the above form.

i.e i need to have individual delete button for every row n when we press the button it need to delete the particular row.

This was selected as the best answer
kiranmutturukiranmutturu

you can acheive that some thing like below

 

<apex:pageBlockTable value="{!testlog1}" var="a" id="pbtable" >
<apex:column value="{!a.Priority__c}" headerValue="Priority"/>
<apex:column value="{!a.Developer__c}" headerValue="Developer"/>
<apex:column value="{!a.Test_Cases__c}" headerValue="Expected_Result"/>
<apex:column value="{!a.Test_Scenario__c}" headerValue="testscenario"/>
<apex:commandButton value="Del"action="{!del}"rerender="table" >
<apex:param name="delname" value="{!a.Test_Scenario__c}" />
</apex:commandLink>
</apex:pageBlockTable>


/* your Delete functionality*/
public PageReference del() {

string delnumber =
ApexPages.CurrentPage().getParameters().get('delnumber');

system.assert( delnumber != null );
integer gone = -1;
integer i = 0;

for ( i=0; i< casenumber ="="" gone =" i;">= 0) {
todeletelist.add(listofobjectitems.remove(gone) );
}
return null;
}

veeru417veeru417

Thank you kiran i will go through and inform you if i get any help.

 

 

Thanks&Regards,

Veerendranath

veeru417veeru417

Hi kiran,

 

I have implemented the Delete functionality .But i have taken Wrapperclass I need your help in writing Test class for that.

I tried to write but it covers only 70%.Can you help me in this plss.

I am posting the Class and Can you help me in it.

 

 

public with sharing class TestClass {
        public boolean isRender = false;
        public integer deleteSpecifier=0;
        public Test_Case_Log__c testLog{get;set;}
        public List<TestCaseLogsClass> gettestlog12(){
        	return TestCaseLogsClassList;
        } 
        public List<Test_Case_Log__c> testCaseLogList = new List<Test_Case_Log__c>(); 
        public TestClass(ApexPages.StandardController controller) {
        testLog = (Test_Case_Log__c)Controller.getRecord();
        }
        public boolean getIsRender(){
                if(TestCaseLogsClassList.size()>0){
                isRender = true;
        }
        else{
                isRender = false;
        }
        return isRender;
        }
        public void add(){
                deleteSpecifier = deleteSpecifier+1;
                TestCaseLogsClassList.add(new TestCaseLogsClass(testLog,deleteSpecifier));  
                testLog = new Test_Case_Log__c();
        }
    	public pagereference save1(){
        	for(Integer i=0;i<TestCaseLogsClassList.size();i++){
            	testCaseLogList.add(TestCaseLogsClassList[i].objTestCaseLog);
        		}
        		if(testCaseLogList.size()>0){
                insert testCaseLogList;
                PageReference pageRef = new PageReference('/a02/o');
                return pageRef;
        		}
        return null;    
    	}
    	public void deleteTestCaseLog(){
        	Integer delcsDetId = Integer.valueOf(System.currentPageReference().getParameters().get('delcsDetId'));
        	for(Integer deleteSpecifier=0;deleteSpecifier<TestCaseLogsClassList.size();deleteSpecifier++){
            	if(delcsDetId == TestCaseLogsClassList[deleteSpecifier].deleteID){
                	TestCaseLogsClassList.remove(deleteSpecifier);
                     break;
                }
        	}
    	}
    	public List<TestCaseLogsClass> TestCaseLogsClassList = new List<TestCaseLogsClass>();
    
    		public class TestCaseLogsClass {
        	public Test_Case_Log__c objTestCaseLog{get;set;}
        	public Integer deleteID{get;set;}
        	public TestCaseLogsClass(Test_Case_Log__c objTestCaseLog1,Integer deleteID1){
                deleteID = deleteID1;
                objTestCaseLog = objTestCaseLog1;
        	}
    	}
}

 Thanks In Advance

 

 

Regards,

Veeru

 

 

 

 

 

JeT2686JeT2686

veeru417 wrote:

yes i have solved the issue ,i have added 

<apex:commandButton value="save" action="{!save1}"  immediate="true"/>

 

so it will skip the validation.

Thanks for your helping behaviour,i have one more issue ,

i need to delete the individual record on the table can you help me in the above form.

i.e i need to have individual delete button for every row n when we press the button it need to delete the particular row.


 

Awesome! Thank you so much for this comment, was looking everywhere on how to get around this. actionRegion works as well but for some reason in my case it did not.

 

Thank You!