Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class addAttendee {
- public Account accounts;
- public Contact del;
- public List<Contact> addattendeeList {get;set;}
- public List<Contact> delattendeeList {get;set;}
- public List<Contact> attendeeList {get;set;}
- public Integer totalCount {get;set;}
- public Integer rowIndex {get;set;}
- public List<Contact> delAttendees {get; set;}
- public addAttendee(ApexPages.StandardController controller) {
- accounts = (Account)controller.getRecord();
- attendeeList = [Select id, firstName, LastName, Email, Phone from Contact where AccountId =: accounts.Id];
- totalCount = attendeeList.size();
- delattendeeList = new List<Contact>();
- delattendees = new List<Contact>();
- }
- public void addRow(){
- addattendeeList = new List<Contact>();
- attendeeList.add(new Contact(AccountId = accounts.Id));
- }
- public PageReference ave(){
- upsert attendeeList;
- delete delattendeeList;
- return (new ApexPages.StandardController(accounts)).view();
- }
- public void deleteRow(){
- rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
- System.debug('rowbe deleted ' + rowIndex );
- System.debug('rowm to be deleted '+attendeeList[rowIndex]);
- del = attendeeList.remove(rowIndex);
- delattendeeList.add(del);
- }
- }
- <apex:page standardController="Account" extensions="addAttendee" sidebar="false">
- <apex:form >
- <apex:pageBlock title="Accounts" id="pb">
- <apex:pageMessages />
- <apex:variable var="rowNumber" value="{!0}"/>
- <apex:pageblockSection columns="1">
- <apex:pageBlockTable title="Contacts" var="acc" value="{!attendeeList}">
- <apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext">
- <apex:outputText value="{0}" style="text-align:center;">
- <apex:param value="{!rowNumber+1}" />
- </apex:outputText>
- </apex:column>
- <apex:column headerValue="First Name" >
- <apex:inputField value="{!acc.FirstName}"/>
- </apex:column>
- <apex:column headerValue="Last Name" >
- <apex:inputField value="{!acc.LastName}"/>
- </apex:column>
- <apex:column headerValue="Phone" >
- <apex:inputField value="{!acc.Phone}"/>
- </apex:column>
- <apex:column headerValue="Email" >
- <apex:inputField value="{!acc.Email}"/>
- </apex:column>
- <apex:column headerValue="Action" >
- <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb">
- <apex:param name="rowIndex" value="{!rowNumber}"/>
- </apex:commandButton>
- <apex:variable var="rowNumber" value="{!rowNumber+1}"/>
- </apex:column>
- </apex:pageBlockTable>
- <apex:commandButton action="{!addRow}" value="Add Attendee" reRender="pb"/>
- </apex:pageblockSection>
- <apex:pageBlockButtons >
- <apex:commandButton value="Save" action="{!ave}" />
- <apex:commandButton value="Cancel" action="{!cancel}"/>
- </apex:pageBlockButtons>
- </apex:pageBlock>
- </apex:form>
- </apex:page>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement