You need to sign in to do that
Don't have an account?
NewBee21
Not getting any error with either controller or VF Page,but once I click preview I am getting the error.
Error on VF page after preview:
The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.
I think it has to do with edit/delete command action link which I added.So kindly review and let me know where to make changes.
**controller**
public with sharing class DisplayAccWithContact3 {
public PageReference DeleteContact() {
return null;
}
public Contact con{get;set;}
public DisplayAccWithContact3() {
con=new contact();
}
public List<Contact> contacts {get; set;}
public string SelectedContactId { get; set; }
public PageReference showContacts() {
contacts = [SELECT Name, Phone, Email FROM Contact WHERE AccountId = :con.accountid];
return null;
}
public void DeleteAccount()
{
// if for any reason we are missing the reference
if (SelectedContactId== null) {
return;
}
// find the account record within the collection
Contact tobeDeleted = null;
for(Contact a : Contacts)
if (a.Id == SelectedContactId) {
tobeDeleted = a;
break;
}
//if account record found delete it
if (tobeDeleted != null) {
Delete tobeDeleted;
}
}
}
**VF Page**
<apex:page sidebar="false" controller="DisplayAccWithContact3">
<apex:form >
<style type="text/css">
.bPageBlock .pbTitle {
width: 100%;
text-align: center; }
</style>
<apex:pageBlock title= "Account Information"/>
<apex:outputText value="Enter Account Name:"></apex:outputText>
<apex:inputfield value="{!con.accountid}"/>
<apex:commandButton value="ShowContacts" action="{!showContacts}" rerender="out" status="mystatus"/><br/>
<apex:actionstatus id="mystatus" starttext="please wait contacts are loading.......">
<apex:facet name="stop">
<apex:outputpanel id="out">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!Contacts}" var="c" rendered="{!con.accountid !=null}">
<apex:column >
<apex:outputLink title="" value="/{!c.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink> |
<a href="javascript:if (window.confirm('Are you sure?')) DeleteAccount('{!c.Id}');" style="font-weight:bold">Del</a>
</apex:column>
<apex:column headerValue="Name">
{!c.Name}
</apex:column>
<apex:column headerValue="Phone">
{!c.Phone}
</apex:column>
<apex:column headerValue="Email">
{!c.Email}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputpanel>
</apex:facet>
</apex:actionstatus>
<apex:actionFunction action="{!DeleteContact}" name="DeleteContact" reRender="form" >
<apex:param name="contactid" value="" assignTo="{!SelectedContactId}"/>
</apex:actionFunction>
</apex:form>
</apex:page>
The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.
I think it has to do with edit/delete command action link which I added.So kindly review and let me know where to make changes.
**controller**
public with sharing class DisplayAccWithContact3 {
public PageReference DeleteContact() {
return null;
}
public Contact con{get;set;}
public DisplayAccWithContact3() {
con=new contact();
}
public List<Contact> contacts {get; set;}
public string SelectedContactId { get; set; }
public PageReference showContacts() {
contacts = [SELECT Name, Phone, Email FROM Contact WHERE AccountId = :con.accountid];
return null;
}
public void DeleteAccount()
{
// if for any reason we are missing the reference
if (SelectedContactId== null) {
return;
}
// find the account record within the collection
Contact tobeDeleted = null;
for(Contact a : Contacts)
if (a.Id == SelectedContactId) {
tobeDeleted = a;
break;
}
//if account record found delete it
if (tobeDeleted != null) {
Delete tobeDeleted;
}
}
}
**VF Page**
<apex:page sidebar="false" controller="DisplayAccWithContact3">
<apex:form >
<style type="text/css">
.bPageBlock .pbTitle {
width: 100%;
text-align: center; }
</style>
<apex:pageBlock title= "Account Information"/>
<apex:outputText value="Enter Account Name:"></apex:outputText>
<apex:inputfield value="{!con.accountid}"/>
<apex:commandButton value="ShowContacts" action="{!showContacts}" rerender="out" status="mystatus"/><br/>
<apex:actionstatus id="mystatus" starttext="please wait contacts are loading.......">
<apex:facet name="stop">
<apex:outputpanel id="out">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!Contacts}" var="c" rendered="{!con.accountid !=null}">
<apex:column >
<apex:outputLink title="" value="/{!c.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink> |
<a href="javascript:if (window.confirm('Are you sure?')) DeleteAccount('{!c.Id}');" style="font-weight:bold">Del</a>
</apex:column>
<apex:column headerValue="Name">
{!c.Name}
</apex:column>
<apex:column headerValue="Phone">
{!c.Phone}
</apex:column>
<apex:column headerValue="Email">
{!c.Email}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputpanel>
</apex:facet>
</apex:actionstatus>
<apex:actionFunction action="{!DeleteContact}" name="DeleteContact" reRender="form" >
<apex:param name="contactid" value="" assignTo="{!SelectedContactId}"/>
</apex:actionFunction>
</apex:form>
</apex:page>