You need to sign in to do that
Don't have an account?
Amit Roy
i want store multiple record at a time using controller
i have a vf page
<apex:page sidebar="false" showHeader="false" controller="definition_overview_controller" tabstyle="Label__c" id="page">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
<script>
function setFocusOnLoad() {}
$(document).ready(function(){
$(".fieldInput").focusin(function() {
var tempObj = $(this).closest('td').prev('td').find('input').val();
if(tempObj.length >0){
sleep(100).then(()=>{
sforce.connection.sessionId='{!GETSESSIONID()}';
var tempList = sforce.apex.execute("ListofLabel","getAllLabels",{Objname:tempObj});
$(".fieldInput").autocomplete({source: tempList});
});
}
});
});
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
</script>
<apex:sectionHeader title="Mapping Object" subtitle="Form" id="header"/>
<apex:form id="form">
<apex:pageBlock id="pageblock" >
<apex:pageBlockTable title="Related List" value="{!label}" var="l" id="pageblocktable">
<apex:column headerValue="Lebal Name" id="col1" >
<apex:outputText value="{!l.name}">
<apex:param value="{!l.name}" AssignTo="{!levelName}"/>
</apex:outputText>
</apex:column>
<apex:column headerValue="SFobject" id="col2">
<apex:inputText value="{!l.FormId__r.Parent_object_Name__c}">
<apex:param value="{!l.formId__r.Parent_object_Name__c}" AssignTo="{!objectName}" />
</apex:inputText>
</apex:column>
<apex:column headerValue="SFField" id="col3">
<apex:inputText value="{!field}" styleClass="fieldInput"/>
</apex:column>
<apex:column >
<apex:commandButton value="Save" action="{!save}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
public class definition_overview_controller{
Mapping__c mapp=new Mapping__c();
//list<Mapping__c> li{get;set;}
public id i;
public String field{get;set;}
//public string x{get;set;}
public String levelname{get;set;}
public string objectname{get;set;}
public definition_overview_controller()
{
i=ApexPages.CurrentPage().getParameters().get('id');
// li=new list<Mapping__c>();
//li.add(mapp);
}
public list<label__C> label;
public list<Label__c> getlabel()
{
label=[select Name,FormId__c,description__c,Label__c,FormId__r.Parent_object_Name__c from Label__c where FormId__c=:i];
return label;
}
public void Save(){
mapp.LabelD__c=levelname;
// System.debug(mapp);
mapp.SFObject__c=objectname;
mapp.SFfield__c=field;
insert mapp;
// li.add(mapp);
/* System.debug(li);
for(integer i=0;i<li.size();i++)
{
insert li;
}*/
}
}
Note : i am not able to store multiple record at a time it show Error-->
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LabelID]: [LabelID]
Error is in expression '{!save}' in component <apex:commandButton> in page visualforcepage_webners_assignment_page2: Class.definition_overview_controller.Save: line 31, column 1
<apex:page sidebar="false" showHeader="false" controller="definition_overview_controller" tabstyle="Label__c" id="page">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
<script>
function setFocusOnLoad() {}
$(document).ready(function(){
$(".fieldInput").focusin(function() {
var tempObj = $(this).closest('td').prev('td').find('input').val();
if(tempObj.length >0){
sleep(100).then(()=>{
sforce.connection.sessionId='{!GETSESSIONID()}';
var tempList = sforce.apex.execute("ListofLabel","getAllLabels",{Objname:tempObj});
$(".fieldInput").autocomplete({source: tempList});
});
}
});
});
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
</script>
<apex:sectionHeader title="Mapping Object" subtitle="Form" id="header"/>
<apex:form id="form">
<apex:pageBlock id="pageblock" >
<apex:pageBlockTable title="Related List" value="{!label}" var="l" id="pageblocktable">
<apex:column headerValue="Lebal Name" id="col1" >
<apex:outputText value="{!l.name}">
<apex:param value="{!l.name}" AssignTo="{!levelName}"/>
</apex:outputText>
</apex:column>
<apex:column headerValue="SFobject" id="col2">
<apex:inputText value="{!l.FormId__r.Parent_object_Name__c}">
<apex:param value="{!l.formId__r.Parent_object_Name__c}" AssignTo="{!objectName}" />
</apex:inputText>
</apex:column>
<apex:column headerValue="SFField" id="col3">
<apex:inputText value="{!field}" styleClass="fieldInput"/>
</apex:column>
<apex:column >
<apex:commandButton value="Save" action="{!save}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
public class definition_overview_controller{
Mapping__c mapp=new Mapping__c();
//list<Mapping__c> li{get;set;}
public id i;
public String field{get;set;}
//public string x{get;set;}
public String levelname{get;set;}
public string objectname{get;set;}
public definition_overview_controller()
{
i=ApexPages.CurrentPage().getParameters().get('id');
// li=new list<Mapping__c>();
//li.add(mapp);
}
public list<label__C> label;
public list<Label__c> getlabel()
{
label=[select Name,FormId__c,description__c,Label__c,FormId__r.Parent_object_Name__c from Label__c where FormId__c=:i];
return label;
}
public void Save(){
mapp.LabelD__c=levelname;
// System.debug(mapp);
mapp.SFObject__c=objectname;
mapp.SFfield__c=field;
insert mapp;
// li.add(mapp);
/* System.debug(li);
for(integer i=0;i<li.size();i++)
{
insert li;
}*/
}
}
Note : i am not able to store multiple record at a time it show Error-->
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LabelID]: [LabelID]
Error is in expression '{!save}' in component <apex:commandButton> in page visualforcepage_webners_assignment_page2: Class.definition_overview_controller.Save: line 31, column 1
BTW: When you're ready to uncomment the code that inserts the list, don't do it in a for-loop. As written, you will insert the list "N" times, where "N" is the number of items in the list. So if you have 3 Mapping__c records, you will try to insert all 3 of them, 3 times. The second attempt will fail, because now the records will have IDs. Just do "insert li;". No for-loop.
Either, change the definition of the "LabelID" field so that it is not required, or change your code so set its value:
mapp.LabelID__c = 'some value';
As for saving a list of records, this is all you need.
<pre>
public void save()
{
insert li;
}
</pre>