You need to sign in to do that
Don't have an account?
Adil_SFDC
Insert Selected rows in Custom Object
HiAll
I have written a VF Page to display Contacts related to Opportunity with check boxes.
Now I want to insert the selected contacts from the VF Page in to a Custom Object called contact_select__c
The custom object is look up to contact
I am stuck at a point where i can assign selected rows contact name to the contact name. If 2 rows are selected I need two Records created.
<apex:page controller="contactoppdisp" tabStyle="Contact" showHeader="false"> <apex:form > <apex:commandButton value="Select Contacts" action="{!SelectContact}"/> <apex:pageBlock > <apex:pageBlockTable value="{!contactDetailsList}" var="con" id="conTableId" rendered="{!NOT(ISNULL(contactDetailsList))}"> <apex:column > <apex:inputCheckbox value="{!con.isSelected}"/> </apex:column> <apex:column headerValue="Contact Name"> <apex:outputText value="{!con.contactName}"/> </apex:column> <apex:column headerValue="Contact Email"> <apex:outputText value="{!con.contactEmail}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
public class contactoppdisp { private Opportunity o; public List<ContactDetails> contactDetailsList {get; set;} public contactoppdisp() { o = [select id, Accountid, name,Email__c from Opportunity where id = :ApexPages.currentPage().getParameters().get('id')]; Contact[] contactList = [select id, name, email from Contact where accountid = :o.Accountid]; if(contactList.size() > 0) { contactDetailsList = new List<ContactDetails>(); for(Contact c: contactList) { ContactDetails cd = new ContactDetails(c.id, c.name, c.email); contactDetailsList.add(cd); } } } public class ContactDetails { public ID contactId {get; set;} public String contactName {get; set;} public String contactEmail {get; set;} public Boolean isSelected {get; set;} public ContactDetails(Id conId,String name,String Email) { contactId = conId; contactName = name; contactEmail = email; isSelected = false; } } public PageReference SelectContact() { ContactSelect__c consec = new ContactSelect__c(); ContactDetails cds = new ContactDetails(consec.id,consec.name,consec.email__c); consec.Name='test'; consec.Contact__c=; insert consec; return null; } }
Please help
you have to loop through your list: (if this helps mark it as a solution :) )