I have a Visualforce page with a page block section which contains multiple rows from different object (Result from query in controller from custom object called "Location__c"). I need to pass the id's of selected rows to controller and perform insert operation to be stored in another custom object called "Desiredlocation__c" with the id's that i received, "Desireclocation__c" is parenting to custom object called "TLead__c". Can anyone help?
My VF
<apex:page docType="html-5.0" controller="incDesiredLocationsController">
<apex:pageMessages />
<apex:form >
<apex:pageBlock title="New Desired Location">
<div align="center">
<apex:commandButton value="Save" action="{!save}"/>
</div>
<apex:pageblockSection title="Select Location" columns="1">
<apex:selectCheckboxes value="{!locationIds}" layout="PageDirection">
<apex:selectOptions value="{!locationSelect}"/>
</apex:selectCheckboxes><br/>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
My controller
public class incDesiredLocationsController {
//add multiple desired location
public List<SelectOption> getlocationSelect(){
List<SelectOption> locationSelect = new List<SelectOption>();
locationIds = new List<Id>();
List<Location__c> dloc = [SELECT City__c,Id, Region__c FROM Location__c where Country__c = 'ID' ORDER BY City__c asc];
for(Location__c loc:dloc)
locationSelect.add(new SelectOption(loc.Id, loc.City__c));
return locationSelect;
}
String[] locationIds = new String[]{};
public String[] getlocationIds () {
return locationIds;
}
public void setlocationIds(String[] locationIds) {
this.locationIds = locationIds;
}
public PageReference save(){
//code block here
}
}