I want to create new contact records by clicking on create new contact button specified for each account record and on clicking of it a popup should come that should display the required fields for creating a contact record and on clicking of save a contact record has to be created and it should be attached to that particular account. Here I am not able to create a contact record at all. Can anyone please solve this.
Controller side:
public Contact objAcc {get;set;}
public string strAccId {get;set;}
public void accActionMethodInController()
{
system.debug('strAccId ======1======> ' +strAccId);
if(strAccId!='' && strAccId!= NULL)
{
system.debug('strAccId ======1======> ' +strAccId);
objAcc = new Contact();
system.debug('objAcc ======1======>' +objAcc);
objAcc.AccountId = strAccId;
system.debug('objAcc.AccountId ======1======>' +objAcc.AccountId);
}
}
public void createContact()
{
insert objAcc;
}
Page:
<apex:outputPanel id="popup">
<div id="selectColumnPopup" style="display:none;">
<div class="popupBackground" layout="block" />
<div class="popupForeground" style="height:40%; width:43%;" >
First Name: <apex:inputField value="{!objAcc.FirstName}" /><br />
Last Name: <apex:inputField value="{!objAcc.LastName}" /><br />
<apex:commandButton value="Save" action="{!createContact}" />
<apex:commandButton value="Cancel" onClick="closePopUp()"/>
</div>
</div>
</apex:outputPanel>
<apex:outputPanel id="acc1" layout="none" rendered="{!accountList.size!=0}">
<apex:repeat id="repeatAccount" value="{!accountList}" var="item">
<tr>
<td class="dataCell"><Input type="button" value="Create New Contact" onclick="displayPopUp('{!item.oAccount.Id}')"/></td>
</tr>
</apex:repeat>
</apex:outputPanel>
</apex:form>
<script>
function displayPopUp(accountId)
{
alert('here : '+accountId);
accActionMethod(accountId);
document.getElementById('selectColumnPopup').style.display = 'block';
}
function closePopUp()
{
document.getElementById('selectColumnPopup').style.display = 'None';
}
</script>
</apex:pageBlock>