You need to sign in to do that
Don't have an account?
Rutvij Pathak 5
unable to pass Account ID to New Contact List
I am creating a Page to add multiple contacts to an Account. The Page is Called by a Button Click on Account Detail Page.'
For now, Contacts are getting Created however, they are not getting Associated to Account.
VISUALFORCE PAGE ---------
<apex:page name="Create Multiple Contacts" controller="AddMultipleContacts" showHeader="true" sidebar="true">
<apex:form >
<apex:pageBlock title="Add Contacts">
<apex:variable var="rowNum" value="{!0}"/>
<apex:pageBlockTable value="{!ContactList}" var="con">
<apex:facet name="footer">
<apex:commandButton value="Add" style="float: right;" action="{!insertRow}" />
</apex:facet>
<apex:column headerValue="First Name">
<apex:inputField value="{!con.FirstName}"/>
</apex:column>
<apex:column headerValue="Last Name">
<apex:inputField value="{!con.LastName}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!con.Phone}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:inputField value="{!con.Email}"/>
</apex:column>
<apex:column headerValue="Action" >
<apex:commandLink style="font-size:12px; font-weight:bold; text-align:center;color:Black;" value="Delete" action="{!delRow}">
<apex:param value="{!rowNum}" name="index" />
</apex:commandLink>
<apex:variable var="rowNum" value="{!rowNum+1}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value="Cancel" onclick="window.history.previous()"/>
<apex:pageBlockButtons location="bottom" >
<apex:commandButton value="Save Contacts" action="{!insertContacts}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
CONTROLLER ---------
public class AddMultipleContacts {
Id AcctID;
public List<Contact> ContactList {get;set;}
public Integer rowNum{get;set;}
public AddMultipleContacts(){
AcctID = ApexPages.currentPage().getParameters().get('AcctID');
ContactList = new List<Contact>();
ContactList.add(new contact());
}
public void insertContacts(){
insert ContactList;
}
public void insertRow(){
ContactList.add(new contact());
}
public void delRow(){
rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
ContactList.remove(rowNum);
}
}
For now, Contacts are getting Created however, they are not getting Associated to Account.
VISUALFORCE PAGE ---------
<apex:page name="Create Multiple Contacts" controller="AddMultipleContacts" showHeader="true" sidebar="true">
<apex:form >
<apex:pageBlock title="Add Contacts">
<apex:variable var="rowNum" value="{!0}"/>
<apex:pageBlockTable value="{!ContactList}" var="con">
<apex:facet name="footer">
<apex:commandButton value="Add" style="float: right;" action="{!insertRow}" />
</apex:facet>
<apex:column headerValue="First Name">
<apex:inputField value="{!con.FirstName}"/>
</apex:column>
<apex:column headerValue="Last Name">
<apex:inputField value="{!con.LastName}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!con.Phone}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:inputField value="{!con.Email}"/>
</apex:column>
<apex:column headerValue="Action" >
<apex:commandLink style="font-size:12px; font-weight:bold; text-align:center;color:Black;" value="Delete" action="{!delRow}">
<apex:param value="{!rowNum}" name="index" />
</apex:commandLink>
<apex:variable var="rowNum" value="{!rowNum+1}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value="Cancel" onclick="window.history.previous()"/>
<apex:pageBlockButtons location="bottom" >
<apex:commandButton value="Save Contacts" action="{!insertContacts}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
CONTROLLER ---------
public class AddMultipleContacts {
Id AcctID;
public List<Contact> ContactList {get;set;}
public Integer rowNum{get;set;}
public AddMultipleContacts(){
AcctID = ApexPages.currentPage().getParameters().get('AcctID');
ContactList = new List<Contact>();
ContactList.add(new contact());
}
public void insertContacts(){
insert ContactList;
}
public void insertRow(){
ContactList.add(new contact());
}
public void delRow(){
rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
ContactList.remove(rowNum);
}
}
Try change your Constrcutor with follwing .
public AddMultipleContacts(){
AcctID = ApexPages.currentPage().getParameters().get('AcctID');
ContactList = new List<Contact>();
ContactList.add(new contact(AccountID=AcctID));
}
Hope the answer helps you.
Thanks
All Answers
Try change your Constrcutor with follwing .
public AddMultipleContacts(){
AcctID = ApexPages.currentPage().getParameters().get('AcctID');
ContactList = new List<Contact>();
ContactList.add(new contact(AccountID=AcctID));
}
Hope the answer helps you.
Thanks
Make you button in account object with below config,
Then Change you apex class with below class,
Let me know if you have any issues
Regards
Thank you so much