You need to sign in to do that
Don't have an account?
Himanshu Ghate
In this code ,when I am creating new record of incentive only monthly code get executed,not working yearly,Quartely,half yearly why?
Apex Code of incentive object-->
public class incentive1
{
public Incentitive1__c incen{get;set;}
public incentive1 ()
{
incen=new Incentitive1__c ();
}
public pagereference Save()
{
if(incen.Name!= Null)
{
insert incen;
}
List<Incentitive1__c> incenlist=new List<Incentitive1__c>();
if(incen.Type__c=='Quarterly')
{
for(integer i=1;i<=3;i++)
{
Incentitive1__c incenQuarterly=new Incentitive1__c (); //making Object to insert the details
incenQuarterly.Name='IncentiveQuarterly'+i;
incenQuarterly.Incentive__c=incen.id;
incenQuarterly.Date__c=incen.Date__c;
incenQuarterly.Type__c=incen.Type__c;
incenQuarterly.TotalAmount__c=(incen.TotalAmount__c/3);
incenlist.add(incenQuarterly);
}insert incenlist;
}
if(incen.Type__c=='Monthly')
{
for(integer i=1;i<=12;i++)
{
Incentitive1__c incenMonthly=new Incentitive1__c ();
incenMonthly.Name='IncentiveMonthly'+i;
incenMonthly.Incentive__c=incen.id;
incenMonthly.Date__c=incen.Date__c;
incenMonthly.Type__c=incen.Type__c;
incenMonthly.TotalAmount__c=(incen.TotalAmount__c/12);
incenlist.add(incenMonthly);
}insert incenlist;
}
if(incen.Type__c=='Yearly')
{
for(integer i=1;i<=1;i++)
{
Incentitive1__c incenYearly=new Incentitive1__c (); //making Object to insert the details
incenYearly.Name='IncentiveYearly'+i;
incenYearly.Incentive__c=incen.id;
incenYearly.Date__c=incen.Date__c;
incenYearly.Type__c=incen.Type__c;
incenYearly.TotalAmount__c=(incen.TotalAmount__c/1);
incenlist.add(incenYearly);
}insert incenlist;
}
if(incen.Type__c=='Half-Yearly')
{
for(integer i=1;i<=6;i++)
{
Incentitive1__c incenHalfYearly=new Incentitive1__c (); //making Object to insert the details
incenHalfYearly.Name='IncentiveHalf-Yearly'+i;
incenHalfYearly.Incentive__c=incen.id;
incenHalfYearly.Date__c=incen.Date__c;
incenHalfYearly.Type__c=incen.Type__c;
incenHalfYearly.TotalAmount__c=(incen.TotalAmount__c/6);
incenlist.add(incenHalfYearly);
}insert incenlist;
}
pagereference pg=new pagereference('/'+incen.id);
return pg;
}
public pagereference Cancel()
{
pagereference pf=new pagereference('https://11com-b-dev-ed.develop.my.salesforce.com/a04/o');
return pf;
}
}
Visualforce page code-->
<apex:page controller="incentive1">
<apex:form >
<apex:sectionHeader title="Incentive Edit" subtitle="NewIncentive"/>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="1">
<apex:inputField value="{!incen.Name}"/>
<apex:inputField value="{!incen.Incentive__c}"/>
<apex:inputField value="{!incen.Date__c}"/>
<apex:inputField value="{!incen.Type__c}"/>
<apex:inputField value="{!incen.TotalAmount__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class incentive1
{
public Incentitive1__c incen{get;set;}
public incentive1 ()
{
incen=new Incentitive1__c ();
}
public pagereference Save()
{
if(incen.Name!= Null)
{
insert incen;
}
List<Incentitive1__c> incenlist=new List<Incentitive1__c>();
if(incen.Type__c=='Quarterly')
{
for(integer i=1;i<=3;i++)
{
Incentitive1__c incenQuarterly=new Incentitive1__c (); //making Object to insert the details
incenQuarterly.Name='IncentiveQuarterly'+i;
incenQuarterly.Incentive__c=incen.id;
incenQuarterly.Date__c=incen.Date__c;
incenQuarterly.Type__c=incen.Type__c;
incenQuarterly.TotalAmount__c=(incen.TotalAmount__c/3);
incenlist.add(incenQuarterly);
}insert incenlist;
}
if(incen.Type__c=='Monthly')
{
for(integer i=1;i<=12;i++)
{
Incentitive1__c incenMonthly=new Incentitive1__c ();
incenMonthly.Name='IncentiveMonthly'+i;
incenMonthly.Incentive__c=incen.id;
incenMonthly.Date__c=incen.Date__c;
incenMonthly.Type__c=incen.Type__c;
incenMonthly.TotalAmount__c=(incen.TotalAmount__c/12);
incenlist.add(incenMonthly);
}insert incenlist;
}
if(incen.Type__c=='Yearly')
{
for(integer i=1;i<=1;i++)
{
Incentitive1__c incenYearly=new Incentitive1__c (); //making Object to insert the details
incenYearly.Name='IncentiveYearly'+i;
incenYearly.Incentive__c=incen.id;
incenYearly.Date__c=incen.Date__c;
incenYearly.Type__c=incen.Type__c;
incenYearly.TotalAmount__c=(incen.TotalAmount__c/1);
incenlist.add(incenYearly);
}insert incenlist;
}
if(incen.Type__c=='Half-Yearly')
{
for(integer i=1;i<=6;i++)
{
Incentitive1__c incenHalfYearly=new Incentitive1__c (); //making Object to insert the details
incenHalfYearly.Name='IncentiveHalf-Yearly'+i;
incenHalfYearly.Incentive__c=incen.id;
incenHalfYearly.Date__c=incen.Date__c;
incenHalfYearly.Type__c=incen.Type__c;
incenHalfYearly.TotalAmount__c=(incen.TotalAmount__c/6);
incenlist.add(incenHalfYearly);
}insert incenlist;
}
pagereference pg=new pagereference('/'+incen.id);
return pg;
}
public pagereference Cancel()
{
pagereference pf=new pagereference('https://11com-b-dev-ed.develop.my.salesforce.com/a04/o');
return pf;
}
}
Visualforce page code-->
<apex:page controller="incentive1">
<apex:form >
<apex:sectionHeader title="Incentive Edit" subtitle="NewIncentive"/>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="1">
<apex:inputField value="{!incen.Name}"/>
<apex:inputField value="{!incen.Incentive__c}"/>
<apex:inputField value="{!incen.Date__c}"/>
<apex:inputField value="{!incen.Type__c}"/>
<apex:inputField value="{!incen.TotalAmount__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Do you mean it is not going into if blocks of Quarterly and remaining except Monthly. Did you cross verify the spellings of those picklists and in the code?
Thanks,