You need to sign in to do that
Don't have an account?
Nikhil Somvanshi
Cannot redirect page to the edit page of related records
Hello Guys!
I am trying to create a functionality in which the i have a list of child records on edit page of parent object. In this list, i have an Edit and Delete button for every record. Deleting the child records is working well but i have issues with Edit, when Edit is clicked, it leads to nowhere. Below is my code. I have a bet on id is not captured by controller method. Please help!
I am trying to create a functionality in which the i have a list of child records on edit page of parent object. In this list, i have an Edit and Delete button for every record. Deleting the child records is working well but i have issues with Edit, when Edit is clicked, it leads to nowhere. Below is my code. I have a bet on id is not captured by controller method. Please help!
Page: <apex:page standardController="Account" tabStyle="Account" extensions="ContactExtension"> <apex:form > <apex:pageblock title="Custom Edit Account Page"> <apex:pageBlockSection title="Information" columns="2"> <apex:inputField value="{!Account.Name}"> <apex:param name="AccountId" value="{!Account.Id}"/> </apex:inputfield> <apex:inputField value="{!Account.Type}"/> <apex:inputField value="{!Account.Industry}"/> <apex:inputField value="{!Account.AnnualRevenue}"/> <apex:inputField value="{!Account.Status__c}"/> <apex:inputField value="{!Account.Completion_Status_For_Opportunity__c}"/> <apex:inputField value="{!Account.Rating}"/> <apex:inputField value="{!Account.Fax}"/> <apex:inputField value="{!Account.Phone}"/> <apex:inputField value="{!Account.Website}"/> <apex:inputField value="{!Account.Ownership}"/> <apex:inputField value="{!Account.NumberOfEmployees}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Address Information" columns="2"> <!-- <apex:panelGrid columns="1"> !--> <apex:inputField value="{!Account.BillingStreet}"/> <apex:inputField value="{!Account.BillingCity}"/> <apex:inputField value="{!Account.BillingState}"/> <apex:inputField value="{!Account.BillingPostalCode}"/> <apex:inputField value="{!Account.BillingStreet}"/> <apex:inputField value="{!Account.BillingCountry}"/> <!-- </apex:panelGrid> --!> <!-- <apex:panelGrid columns="1"> !--> <apex:inputField value="{!Account.ShippingStreet}"/> <apex:inputField value="{!Account.ShippingCity}"/> <apex:inputField value="{!Account.ShippingState}"/> <apex:inputField value="{!Account.ShippingPostalCode}"/> <apex:inputField value="{!Account.ShippingStreet}"/> <apex:inputField value="{!Account.ShippingCountry}"/> <!-- </apex:panelGrid> !--> </apex:pageBlockSection> <apex:pageBlocksection title="Additional Information"> <apex:inputField value="{!Account.CustomerPriority__c}"/> <apex:inputField value="{!Account.SLAExpirationDate__c}"/> <apex:inputField value="{!Account.NumberofLocations__c}"/> <apex:inputField value="{!Account.SLASerialNumber__c}"/> <apex:inputField value="{!Account.SLA__c}"/> <apex:inputField value="{!Account.UpsellOpportunity__c}"/> </apex:pageBlocksection> <apex:pageBlockSection title="Description"> <apex:inputField value="{!Account.Description}"/> </apex:pageBlockSection> <apex:pageBlockButtons location="Top"> <apex:commandButton value="Save" Action="{!Save}"/> <apex:commandButton value="Cancel" Action="{!Cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Related Contacts"> </apex:pageBlockSection> <apex:commandButton value="Display Contacts" action="{!Check}" reRender="ajax" id="actionRender"/> <apex:pageBlockTable value="{!Conlist}" var="c" id="ajax"> <apex:column headerValue="Action"> <apex:commandButton value="Edit"> <apex:actionSupport event="onchange" action="{!EditRedirect}" > <apex:param value="{!c.Id}" name="ContactToEdit"/> </apex:actionSupport> </apex:commandButton> <apex:commandButton value="Delete" action="{!deletecontact}" reRender="ajax"> <apex:param value="{!c.id}" name="ContactToDelete"/> </apex:commandButton> </apex:column> <apex:column value="{!c.Name}"/> <apex:column value="{!c.Phone}"/> <apex:column value="{!c.Active__c}"/> </apex:pageblock> </apex:form> </apex:page> Class: public class ContactExtension { Public List<Contact> Conlist {set;get;} Public String AccId {get;set;} Public String var; Public ContactExtension(ApexPages.StandardController sc) { AccId = ApexPages.CurrentPage().getParameters().get('AccountId'); } Public void Check() { Conlist = [select id,name,Phone,Active__c from Contact where AccountId=:AccId]; } Public void deletecontact() { String ConId = ApexPages.CurrentPage().GetParameters().Get('ContactToDelete'); List <Contact> ContactList = [select id,name from contact where id =: ConId]; Delete ContactList; Check(); } Public Boolean newId{get;set;} Public PageReference EditRedirect() { var = ApexPages.CurrentPage().GetParameters().Get('ContactToEdit'); return new Pagereference ('/'+var+'/e').setredirect(true); } }