You need to sign in to do that
Don't have an account?
vijay333551.3966074804040708E12
How to get id for record on commandlink press ?
Hi All,
I am get getting list of accounts as command links in visual force page once i click a particualr account releated contact details record names are
displayed as command links again if i click on particular contact i need to redirect contact record detail page instead of it i am redirecting to home
page i guess i am getting home page ID instead of Contact ID and help me how to get record ID on CommandLink Click
<apex:page controller="MyController">
<apex:form >
<apex:pageBlock title="Accounts Info">
<apex:pageBlockSection title="Accouns">
<apex:dataList value="{!myaccounts}" var="acct">
<apex:commandlink action="{! accountClicked}" rerender="ContactDetail">
<apex:outputText value="{! acct.name}"/>
<apex:param name="id" value="{! acct.Id}" assignTo="{!selectedAccount}"/>
</apex:commandLink>
</apex:dataList>
</apex:pageBlockSection>
<apex:pageBlockSection title="Contact Records">
<apex:outputPanel id="ContactDetail">
<apex:repeat value="{! contactsInformation}" var="contact">
<p><apex:commandLink action="{!contactClicked}">
<apex:outputText value="{! contact.Name}"/>
<apex:param name="id1" value="{!contact.id}" assignTo="{!selectedContact}"/>
</apex:commandLink></p>
</apex:repeat>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
---contrlooer code---
public class MyController {
public Id selectedAccount { get; set; }
public List<Contact> contactsInformation { get; set; }
public Id selectedContact { get; set; }
public PageReference contactClicked() {
List<Contact> id = [select id from contact where id =:selectedContact];
PageReference nextpage = new PageReference('https://na15.salesforce.com/?id='+id);
return nextpage;
}
public List<Account> getMyaccounts() {
return [SELECT Id, Name, AccountNumber FROM Account ORDER BY
LastModifiedDate DESC LIMIT 10];
}
public void accountClicked() {
contactsInformation = [SELECT Name,id FROM Contact
WHERE AccountID = :selectedAccount];
}
}
I am get getting list of accounts as command links in visual force page once i click a particualr account releated contact details record names are
displayed as command links again if i click on particular contact i need to redirect contact record detail page instead of it i am redirecting to home
page i guess i am getting home page ID instead of Contact ID and help me how to get record ID on CommandLink Click
<apex:page controller="MyController">
<apex:form >
<apex:pageBlock title="Accounts Info">
<apex:pageBlockSection title="Accouns">
<apex:dataList value="{!myaccounts}" var="acct">
<apex:commandlink action="{! accountClicked}" rerender="ContactDetail">
<apex:outputText value="{! acct.name}"/>
<apex:param name="id" value="{! acct.Id}" assignTo="{!selectedAccount}"/>
</apex:commandLink>
</apex:dataList>
</apex:pageBlockSection>
<apex:pageBlockSection title="Contact Records">
<apex:outputPanel id="ContactDetail">
<apex:repeat value="{! contactsInformation}" var="contact">
<p><apex:commandLink action="{!contactClicked}">
<apex:outputText value="{! contact.Name}"/>
<apex:param name="id1" value="{!contact.id}" assignTo="{!selectedContact}"/>
</apex:commandLink></p>
</apex:repeat>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
---contrlooer code---
public class MyController {
public Id selectedAccount { get; set; }
public List<Contact> contactsInformation { get; set; }
public Id selectedContact { get; set; }
public PageReference contactClicked() {
List<Contact> id = [select id from contact where id =:selectedContact];
PageReference nextpage = new PageReference('https://na15.salesforce.com/?id='+id);
return nextpage;
}
public List<Account> getMyaccounts() {
return [SELECT Id, Name, AccountNumber FROM Account ORDER BY
LastModifiedDate DESC LIMIT 10];
}
public void accountClicked() {
contactsInformation = [SELECT Name,id FROM Contact
WHERE AccountID = :selectedAccount];
}
}
public PageReference contactClicked() {
return new PageReference('https://na15.salesforce.com/?id='+selectedContact);
}
To avoid hardcoding check this link -:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_url.htm
If this resolves your issue, kindly MARK it as SOLVED.