You need to sign in to do that
Don't have an account?
Arnold Joseph Todas
Edit Contact base on Account
How can i edit contact base on account here is my code:
When i click edit it should edit the specific contact in row.
Thanks!
AJ
<apex:page sidebar="false" standardController="Account" recordSetVar="accounts" tabstyle="account" extensions="DisplayContact"> <img src="{!$Resource.OnePiece}" /> <script> var lastRow; function highlight(elem){ if(lastRow != undefined) elem.style.fontWeight = 'bold'; lastRow = elem; } </script> <apex:form id="frm" > <apex:pageBlock title="Account" id="accounts"> <apex:pageBlockTable value="{!accounts}" var="a" id="list" rules="rows" onRowClick="highlight(this);"> <apex:column headerValue="Account Name"> <apex:commandLink rerender="contactDetails" value=" {!a.Name}" action="{!ContactLists}"> <apex:param name="id" value="{!a.id}"/> </apex:commandLink> </apex:column> <apex:column value="{!a.type}" /> <apex:column value="{!a.billingstreet}"/> <apex:column value="{!a.billingCity}" /> <apex:column value="{!a.billingCountry}" /> <apex:column value="{!a.billingPostalCode}"/> <apex:column value="{!a.createdById}"/> </apex:pageBlockTable> <center> <!--<apex:commandButton value="Show Contacts"/>--> <apex:commandButton value="Hide Contacts" action="{!EditContact}" rerender="contactDetails" /> </center> </apex:pageBlock> <apex:pageBlock title="Contact" id="contacts"> <apex:outputPanel id="contactDetails" > <apex:pageBlockTable value="{!conList}" var="con" id="conlist" title="Contact"> <apex:column value="{!con.Name}"/> <apex:Column value="{!con.Phone}" /> <apex:Column value="{!con.Email}" /> <apex:column > <apex:commandLink action="{!Edit}" > Edit </apex:commandLink> </apex:column> <!-- <apex:column headerValue="Edit Record"> <apex:commandLink rerender="contacts" value="edit" action="{!ContactLists}"> <apex:param name="id" value="{!edit.id}"/> </apex:commandLink> </apex:column>--> </apex:pageBlockTable> <center><apex:commandButton value="Add New Contact" rendered="{!showResults}" action="{!AddnewCont}"/></center> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page> ------------------------------------------------------------------------------------ public with sharing class DisplayContact { public DisplayContact(ApexPages.StandardSetController controller) { } public List<Contact> conList {get;set;} public List<Account> accList{get;set;} public Contact con{get; set;} public Boolean showResults {get; set;} public PageReference ContactLists() { showResults = true; if(ApexPages.currentPage().getParameters().get('id') != null) conList = [Select id,Name,Phone,Email from contact where accountId =: ApexPages.currentPage().getParameters().get('id')]; accList = [Select id From Account Where Id=:ApexPages.currentPage().getParameters().get('id')]; System.debug('*****' + conList); System.debug('*****' + accList); return null; } public PageReference EditContact(){ conList = null; PageReference hide = new PageReference('https://c.ap0.visual.force.com/apex/AccountSearchContact'); showResults = false; return null; } public PageReference AddnewCont(){ if(ApexPages.currentPage().getParameters().get('id') != null) accList = [Select id From Account Where Id=:ApexPages.currentPage().getParameters().get('id')]; for(Account a: accList ){ PageReference addnew = new PageReference('https://ap.salesforce.com/003/e?retURL=%2F' + a.Id+ '&accid='+a.Id); return addnew; } return null; } public PageReference Edit(){ if(ApexPages.currentPage().getParameters().get('id') != null) conList = [Select id,Name,Phone,Email, AccountId from Contact where AccountId =: ApexPages.currentPage().getParameters().get('id')]; System.debug('&&'+conList); for(Contact c: conList){ PageReference addnew = new PageReference('https://ap.salesforce.com/' + c.Id ); return addnew; } return null; } }
When i click edit it should edit the specific contact in row.
Thanks!
AJ
http://th3silverlining.com/2009/06/12/salesforce-bugs-you/
I Have made some Changes
Try This..
<apex:page sidebar="false" standardController="Account" recordSetVar="accounts" tabstyle="account" extensions="DisplayContact">
<!--<img src="{!$Resource.OnePiece}" />-->
<script>
var lastRow;
function highlight(elem){
if(lastRow != undefined)
elem.style.fontWeight = 'bold';
lastRow = elem;
}
</script>
<apex:form id="frm" >
<apex:pageBlock title="Account" id="accounts" mode="edit">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
<apex:pageBlockTable value="{!accounts}" var="a" id="list" rules="rows" onRowClick="highlight(this);">
<apex:column headerValue="Account Name">
<apex:commandLink rerender="contactDetails" value=" {!a.Name}" action="{!ContactLists}">
<apex:param name="id" value="{!a.id}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!a.type}" />
<apex:column value="{!a.billingstreet}"/>
<apex:column value="{!a.billingCity}" />
<apex:column value="{!a.billingCountry}" />
<apex:column value="{!a.billingPostalCode}"/>
<apex:column value="{!a.createdById}"/>
</apex:pageBlockTable>
<center>
<!--<apex:commandButton value="Show Contacts"/>-->
<apex:commandButton value="Hide Contacts" action="{!EditContact}" rerender="contactDetails" />
</center>
</apex:pageBlock>
<apex:pageBlock title="Contact" id="contacts">
<apex:outputPanel id="contactDetails" >
<apex:pageBlockTable value="{!conList}" var="con" id="conlist" title="Contact">
<apex:column headervalue="First Name">
<apex:outputField value="{!con.FirstName}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>
<apex:column headervalue="Last Name">
<apex:outputField value="{!con.LastName}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>
<apex:Column headervalue="phone">
<apex:outputField value="{!con.phone}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
hideOnEdit="test" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>
<apex:Column headervalue="Email">
<apex:outputField value="{!con.Email}">
<apex:inlineEditSupport showOnEdit="test"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField >
</apex:Column>
<apex:column>
<apex:commandLink onclick="javascript.void(0);" id="test"> Edit </apex:commandLink>
</apex:column>
</apex:pageBlockTable>
<center><apex:commandButton value="Add New Contact" rendered="{!showResults}" action="{!AddnewCont}"/>
<apex:commandButton value="Save" rendered="{!showResults}" action="{!QuickSave}"/>
</center>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
=============================Class========================
public with sharing class DisplayContact {
public DisplayContact(ApexPages.StandardSetController controller) {
}
public List<Contact> conList {get;set;}
public List<Account> accList{get;set;}
public Contact con{get; set;}
public Boolean showResults {get; set;}
public PageReference ContactLists()
{
showResults = true;
if(ApexPages.currentPage().getParameters().get('id') != null)
conList = [Select id,Name,firstname,lastname,Phone,Email from contact where accountId =: ApexPages.currentPage().getParameters().get('id')];
accList = [Select id From Account Where Id=:ApexPages.currentPage().getParameters().get('id')];
System.debug('*****' + conList);
System.debug('*****' + accList);
return null;
}
public PageReference EditContact(){
conList = null;
PageReference hide = new PageReference('https://c.ap0.visual.force.com/apex/AccountSearchContact');
showResults = false;
return null;
}
public PageReference AddnewCont(){
if(ApexPages.currentPage().getParameters().get('id') != null)
accList = [Select id From Account Where Id=:ApexPages.currentPage().getParameters().get('id')];
for(Account a: accList ){
PageReference addnew = new PageReference('https://ap.salesforce.com/003/e?retURL=%2F' + a.Id+ '&accid='+a.Id);
return addnew;
}
return null;
}
public PageReference Edit(){
if(ApexPages.currentPage().getParameters().get('id') != null)
conList = [Select id,Name,Phone,Email, AccountId from Contact where AccountId =: ApexPages.currentPage().getParameters().get('id')];
System.debug('&&'+conList);
for(Contact c: conList){
PageReference addnew = new PageReference('https://ap.salesforce.com/' + c.Id );
return addnew;
}
return null;
}
}
Method
public pagereference SaveRecords(){
try{
update conList;
}
catch(Exception ex){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error :'+ex.getMessage()));
}
return null;
}