You need to sign in to do that
Don't have an account?
Kyo
I have a problem with the Delete Record and Standard Field.
Hey,
I created the AddRow () Function. but I can not delete a Record.
public class NewAddProducts{ public List<Case> Cases {get; set;} public NewAddProducts(){ Cases = new List<Case>(); Case CaseAdd = new Case(); if(Apexpages.Currentpage().getParameters().get('ID')!=null) { CaseAdd.Contacts__c = Apexpages.Currentpage().getParameters().get('id'); } //accts.add(new Opportunities_Line_Item__c()); Cases.add(CaseAdd); } public void addrow(){ Case CaseAdd = new Case(); if(Apexpages.Currentpage().getParameters().get('ID')!=null) { CaseAdd.Contacts__c = Apexpages.Currentpage().getParameters().get('id'); } Cases.add(CaseAdd); //accts.add(new Opportunities_Line_Item__c()); } public PageReference save(){ insert Cases; PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')); home.setRedirect(true); return home; } public PageReference Cancel() { PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')); returnPage.setRedirect(true); return returnPage; } }
And I can not come available Standard Field.
Standard Object : Case
Standard Field Name : Contact
Type : Lookup
Error: Compile Error: Illegal assignment from String to SOBJECT:Contact at line 9 column 13
public class NewAddProducts{ public List<Case> Cases {get; set;} public NewAddProducts(){ Cases = new List<Case>(); Case CaseAdd = new Case(); if(Apexpages.Currentpage().getParameters().get('ID')!=null) { CaseAdd.Contact = Apexpages.Currentpage().getParameters().get('id'); } //accts.add(new Opportunities_Line_Item__c()); Cases.add(CaseAdd); } public void addrow(){ Case CaseAdd = new Case(); if(Apexpages.Currentpage().getParameters().get('ID')!=null) { CaseAdd.Contact = Apexpages.Currentpage().getParameters().get('id'); } Cases.add(CaseAdd); //accts.add(new Opportunities_Line_Item__c()); } public PageReference save(){ insert Cases; PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')); home.setRedirect(true); return home; } public PageReference Cancel() { PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')); returnPage.setRedirect(true); return returnPage; } }
I hope you will help me.
Thank you.
If you look at your add row link, you are rerendering the table:
However, the deleteRow button only rerenders the error:
So even though you have changed the cases list, you haven't redrawn it on the page. Add the table into the rerender attribute and that should solve the problem.
All Answers
Case.Contact is a reference to a contact, whereas you are assigning an id to it.
Try:
Hey Bob,
Ok Standard Field Successful.
Thank you so much.
but Delete Record I have a problem with it so much.
Are you looking to delete out an entry from your Cases list?
Page
I want to remove my Add New Record.
Is it only the last record that you want to delete, or could it be any record in the list?
I'm assuming its the latter - you'll need to ensure that there is a field on the Case that uniquely identifies it. Then you can pass back this field from the page when the user clicks the delete button.
If you don't have a unique field, you can look at changing your list of cases to be a list of wrapper classes that contains the case and a unique index. Then the page can pass through the unique index when the delete button is clicked.
In either of the above, your controller code will then iterate the list, locate the element with the unique id, and remove it from the list.
Yes, it only the last record.
I want to delete the last record, but the function must be done before the save.
Thank you so much.
If its always the last record, just add a Delete button to the page that calls an action method to remove the final entry. Something like.
Hey, I'm sorry to annoy you again.
I have done as you recommend, but did not missing Record.
Thank you so much.
If you look at your add row link, you are rerendering the table:
However, the deleteRow button only rerenders the error:
So even though you have changed the cases list, you haven't redrawn it on the page. Add the table into the rerender attribute and that should solve the problem.
Perfect! Thank you Bob.