Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. public class addAttendee {
  2. public Account accounts;
  3. public Contact del;
  4. public List<Contact> addattendeeList {get;set;}
  5. public List<Contact> delattendeeList {get;set;}
  6. public List<Contact> attendeeList {get;set;}
  7. public Integer totalCount {get;set;}
  8. public Integer rowIndex {get;set;}
  9.  
  10. public List<Contact> delAttendees {get; set;}
  11. public addAttendee(ApexPages.StandardController controller) {
  12.  
  13. accounts = (Account)controller.getRecord();
  14. attendeeList = [Select id, firstName, LastName, Email, Phone from Contact where AccountId =: accounts.Id];
  15. totalCount = attendeeList.size();
  16.  
  17. delattendeeList = new List<Contact>();
  18. delattendees = new List<Contact>();
  19. }
  20.  
  21. public void addRow(){
  22. addattendeeList = new List<Contact>();
  23. attendeeList.add(new Contact(AccountId = accounts.Id));
  24. }
  25.  
  26. public PageReference ave(){
  27.  
  28. upsert attendeeList;
  29. delete delattendeeList;
  30. return (new ApexPages.StandardController(accounts)).view();
  31. }
  32.  
  33. public void deleteRow(){
  34.  
  35. rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
  36. System.debug('rowbe deleted ' + rowIndex );
  37. System.debug('rowm to be deleted '+attendeeList[rowIndex]);
  38. del = attendeeList.remove(rowIndex);
  39. delattendeeList.add(del);
  40.  
  41. }
  42. }
  43.  
  44. <apex:page standardController="Account" extensions="addAttendee" sidebar="false">
  45. <apex:form >
  46. <apex:pageBlock title="Accounts" id="pb">
  47. <apex:pageMessages />
  48. <apex:variable var="rowNumber" value="{!0}"/>
  49. <apex:pageblockSection columns="1">
  50. <apex:pageBlockTable title="Contacts" var="acc" value="{!attendeeList}">
  51.  
  52. <apex:column headerValue="No." style="width:20px; text-align:center;" headerClass="centertext">
  53. <apex:outputText value="{0}" style="text-align:center;">
  54. <apex:param value="{!rowNumber+1}" />
  55. </apex:outputText>
  56. </apex:column>
  57. <apex:column headerValue="First Name" >
  58. <apex:inputField value="{!acc.FirstName}"/>
  59. </apex:column>
  60. <apex:column headerValue="Last Name" >
  61. <apex:inputField value="{!acc.LastName}"/>
  62. </apex:column>
  63. <apex:column headerValue="Phone" >
  64. <apex:inputField value="{!acc.Phone}"/>
  65. </apex:column>
  66. <apex:column headerValue="Email" >
  67. <apex:inputField value="{!acc.Email}"/>
  68. </apex:column>
  69. <apex:column headerValue="Action" >
  70. <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb">
  71. <apex:param name="rowIndex" value="{!rowNumber}"/>
  72. </apex:commandButton>
  73. <apex:variable var="rowNumber" value="{!rowNumber+1}"/>
  74. </apex:column>
  75. </apex:pageBlockTable>
  76. <apex:commandButton action="{!addRow}" value="Add Attendee" reRender="pb"/>
  77. </apex:pageblockSection>
  78. <apex:pageBlockButtons >
  79. <apex:commandButton value="Save" action="{!ave}" />
  80. <apex:commandButton value="Cancel" action="{!cancel}"/>
  81. </apex:pageBlockButtons>
  82. </apex:pageBlock>
  83. </apex:form>
  84. </apex:page>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement