You need to sign in to do that
Don't have an account?

save multiple records at same time
i want to same multiple records at one click im have following problems
1 dublicate records are creating
2 all records is save with same value
apex code
<apex:page controller="sample1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!task}" var="p">
<apex:column headerValue="values">
<apex:outputText value="{!p}">
</apex:outputText>
</apex:column>
<apex:column headerValue="15%">
<apex:inputText value="{!a}" />
</apex:column>
<apex:column headerValue="20%">
<apex:inputtext value="{!b}"/>
</apex:column>
<apex:column headerValue="30%">
<apex:inputtext value="{!c}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
controller
public class sample1
{
List<String> s=new List<String>();
public String x{get;set;}
public Integer a{get;set;}
public Integer b{get;set;}
public Integer c{get;set;}
public List<String> getTask()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Account.task__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
//options.add(new SelectOption(f.getLabel(), f.getValue()));
//System.debug(f.getLabel());
s.add(f.getValue());
}
return s;
}
public void save()
{
for(String x:s)
{
task__c t = new task__c(Name=x,X15__c=a,X20__c=b,X30__c=c);
try
{
insert t;
}
catch(Exception e)
{
ApexPages.addMessages(e);
}
}
}
}
1 dublicate records are creating
2 all records is save with same value
apex code
<apex:page controller="sample1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!task}" var="p">
<apex:column headerValue="values">
<apex:outputText value="{!p}">
</apex:outputText>
</apex:column>
<apex:column headerValue="15%">
<apex:inputText value="{!a}" />
</apex:column>
<apex:column headerValue="20%">
<apex:inputtext value="{!b}"/>
</apex:column>
<apex:column headerValue="30%">
<apex:inputtext value="{!c}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
controller
public class sample1
{
List<String> s=new List<String>();
public String x{get;set;}
public Integer a{get;set;}
public Integer b{get;set;}
public Integer c{get;set;}
public List<String> getTask()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Account.task__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
//options.add(new SelectOption(f.getLabel(), f.getValue()));
//System.debug(f.getLabel());
s.add(f.getValue());
}
return s;
}
public void save()
{
for(String x:s)
{
task__c t = new task__c(Name=x,X15__c=a,X20__c=b,X30__c=c);
try
{
insert t;
}
catch(Exception e)
{
ApexPages.addMessages(e);
}
}
}
}
task__c t = new task__c(Name=x,X15__c=a,X20__c=b,X30__c=c); - a, b and c are not having any value
Thanks
public class insertdynamic{
public integer i {set;get;}
public list<account>acc{set;get;}
public string name{set;get;}
public string phone {set;get;}
public integer reveune{set;get;}
public void dynamic(){
acc=new list<account>();
for( i=1;i<5;i++){
account a=new account();
a.name=name+i:
a.phone=phone;
a.AnnualRevenue=reveune;
acc.add(a)
}
if(i==1){
insert acc;
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.error, 'this is duplicate values ');
}
public pagereferance next(){
pagereferance p=new pagereferance ('apex/nextpage');
return p;
}
use this page for enter next person details vf for main
<apex:page controller="insertdynamic">
<apex:form>
<apex:inputtext value="{!name}"/>
<apex:inputtext value="{!phone}"/>
<apex:inputtext value="{!reveune}"/>
<apex:commadbutton value="save" action="{!dynamic}"/>
<apex:commandbutton value="next" action="{!next}"/>
</apex:form>
</apex:page>
vf page name=========nextpage
<apex:inputtext value="{!name}"/>
<apex:inputtext value="{!phone}"/>
<apex:inputtext value="{!reveune}"/>
<apex:commadbutton value="save" action="{!dynamic}"/>
<apex:commandbutton value="next" action="{!next}"/>
i hope this is use full to u tell me