• kloudroot
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

Hello,

 

I currently have a VF page and custom controller.  The page has 5 input values which are then written back to the custom Object I have created.  There are also Save and Cancel buttons.  Everything works fine, except in the case where no values are entered and the user clicks the Save button.  I would like to have a custom message appear telling them that they either need to enter a value or click cancel.  Right now I get a System.DmlException error.  This seems like it would be a fairly simple thing to do but I am having a lot of trouble figuring it out.  Any help would be appreciated!  Below is my code:

 

VF Page

 

<apex:page standardController="Population_Assumption__c" tabStyle="Population_Assumption__c" extensions="CustomOppController"
 sidebar="False" Title="Update Population Assumptions" recordSetVar="opps" id="mupop">
    <apex:form id="muform">
    <style type="text/css">
    .bPageBlock.pbBody { background-color:#0000CD; }
    .format { font-style:italic; font-weight:bold; color:#0000CD; }
    .box { background-color:LightSteelBlue; }
    .button { text-align:center; padding-top:4px; }
    </style>

        <apex:pageBlock title="UPDATE POPULATION ASSUMPTIONS" mode="edit" id="mub1">
             <apex:pageBlockSection columns="2">
             <apex:outputLabel for="EmployeePop" styleClass="format" value="Eligible Employee Population: ">
                <apex:inputText styleClass="box" value="{!NewEEVal}" id="EmployeePop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

             <apex:outputLabel for="SpousePop" styleClass="format" value="Eligible Spouse Population: ">
                <apex:inputText styleClass="box" value="{!NewSPVal}" id="SpousePop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

            <apex:outputLabel for="DepPop" styleClass="format" value="Eligible Dependents Population: ">
                <apex:inputText styleClass="box" value="{!NewDEPVal}" id="DepPop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

            <apex:outputLabel for="SeniorPop" styleClass="format" value="Eligible Seniors Population: ">
                <apex:inputText styleClass="box" value="{!NewSENVal}" id="SeniorPop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

            <apex:outputLabel for="OtherPop" styleClass="format" value="Eligible Other Population: ">
                <apex:inputText styleClass="box" value="{!NewOTHVal}" id="OtherPop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR><BR></BR><BR></BR>

             </apex:pageBlockSection>
            <apex:pageBlockButtons location="top">
                <apex:commandButton styleClass="button" style="background:DarkSeaGreen" value="Save" action="{!quicksave}"/>
                <apex:commandButton styleClass="button" style="background:DarkSeaGreen" value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>

         <apex:pageBlockTable value="{!opps}" var="p">
            <apex:column value="{!p.Name}"/>
            <apex:column value="{!p.EE_Eligible_Population__c}"/>
            <apex:column value="{!p.Spouse_Eligible_Population__c}"/>
            <apex:column value="{!p.Dependents_Eligible_Population__c}"/>
            <apex:column value="{!p.Seniors_Eligible_Population__c}"/>
            <apex:column value="{!p.Other_Eligible_Population__c}"/>

        </apex:pageBlockTable>
           
        </apex:pageBlock>

    </apex:form>
</apex:page>

 

 

Controller

 

public class CustomOppController{

    public CustomOppController(ApexPages.StandardSetController controller) {
oppid=System.currentPageReference().getParameters().get('id');
    }

public List<Population_Assumption__c> PopulationInfo{get;set;}
//public List<Opportunity> OppsRecord{get; set;}
public String oppid{get; set;}
Public Decimal NewEEVal{get;set;}
Public Decimal NewSPVal{get;set;}
Public Decimal NewDEPVal{get;set;}
Public Decimal NewSENVal{get;set;}
Public Decimal NewOTHVal{get;set;}
public CustomOppController()

{
//oppid=System.currentPageReference().getParameters().get('id');
//OppsRecord=[Select id from Opportunity where id=:oppid];
//ApexPages.StandardSetController controller
}
//oppid=System.currentPageReference().getParameters().get('id');
public PageReference quicksave()
{
PopulationInfo=new List<Population_Assumption__c>();
   //oppid=System.currentPageReference().getParameters().get('id');
   for(Population_Assumption__c pop :[Select EE_Eligible_Population__c,Spouse_Eligible_Population__c,Dependents_Eligible_Population__c,
   Seniors_Eligible_Population__c,Other_Eligible_Population__c from Population_Assumption__c where Opportunity__c=:oppid])
    {
      IF (NewEEVal != null) {
      pop.EE_Eligible_Population__c = NewEEVal;
      }
      IF (NewSPVal != null) {
      pop.Spouse_Eligible_Population__c = NewSPVal;
      }
      IF (NewDEPVal != null) {
      pop.Dependents_Eligible_Population__c = NewDEPVal;
      }
      IF (NewSENVal != null) {
      pop.Seniors_Eligible_Population__c = NewSENVal;
      }
      IF (NewOTHVal != null) {
      pop.Other_Eligible_Population__c = NewOTHVal;
      }
     
      PopulationInfo.add(pop );
    }

update PopulationInfo;   

PageReference Newpage=new PageReference('/'+oppid);
return NewPage;

}
}

 

Hi -  

I am developing a managed package.  It is complete, but during testing we realized that users who can't delete certain objects are unable to use the app.  I want them to be able to use it WITHOUT the delete permission.  I was wondering if there is a way to overide their CRUD perms in Apex.  I tried System.runsAs() but that only works for tests.  Any suggestions would be greatly appreciated.  

 

 

Hi -   

 

I am developing a managed package.  It is complete, but during testing we realized that users who can't delete certain objects are unable to use the app.  I want them to be able to use it WITHOUT the delete permission.  I was wondering if there is a way to overide their CRUD perms in Apex.  I tried System.runsAs() but that only works for tests.  Any suggestions would be greatly appreciated.  

Hello,

 

I currently have a VF page and custom controller.  The page has 5 input values which are then written back to the custom Object I have created.  There are also Save and Cancel buttons.  Everything works fine, except in the case where no values are entered and the user clicks the Save button.  I would like to have a custom message appear telling them that they either need to enter a value or click cancel.  Right now I get a System.DmlException error.  This seems like it would be a fairly simple thing to do but I am having a lot of trouble figuring it out.  Any help would be appreciated!  Below is my code:

 

VF Page

 

<apex:page standardController="Population_Assumption__c" tabStyle="Population_Assumption__c" extensions="CustomOppController"
 sidebar="False" Title="Update Population Assumptions" recordSetVar="opps" id="mupop">
    <apex:form id="muform">
    <style type="text/css">
    .bPageBlock.pbBody { background-color:#0000CD; }
    .format { font-style:italic; font-weight:bold; color:#0000CD; }
    .box { background-color:LightSteelBlue; }
    .button { text-align:center; padding-top:4px; }
    </style>

        <apex:pageBlock title="UPDATE POPULATION ASSUMPTIONS" mode="edit" id="mub1">
             <apex:pageBlockSection columns="2">
             <apex:outputLabel for="EmployeePop" styleClass="format" value="Eligible Employee Population: ">
                <apex:inputText styleClass="box" value="{!NewEEVal}" id="EmployeePop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

             <apex:outputLabel for="SpousePop" styleClass="format" value="Eligible Spouse Population: ">
                <apex:inputText styleClass="box" value="{!NewSPVal}" id="SpousePop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

            <apex:outputLabel for="DepPop" styleClass="format" value="Eligible Dependents Population: ">
                <apex:inputText styleClass="box" value="{!NewDEPVal}" id="DepPop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

            <apex:outputLabel for="SeniorPop" styleClass="format" value="Eligible Seniors Population: ">
                <apex:inputText styleClass="box" value="{!NewSENVal}" id="SeniorPop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR>

            <apex:outputLabel for="OtherPop" styleClass="format" value="Eligible Other Population: ">
                <apex:inputText styleClass="box" value="{!NewOTHVal}" id="OtherPop">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputText></apex:outputLabel><BR></BR><BR></BR><BR></BR>

             </apex:pageBlockSection>
            <apex:pageBlockButtons location="top">
                <apex:commandButton styleClass="button" style="background:DarkSeaGreen" value="Save" action="{!quicksave}"/>
                <apex:commandButton styleClass="button" style="background:DarkSeaGreen" value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>

         <apex:pageBlockTable value="{!opps}" var="p">
            <apex:column value="{!p.Name}"/>
            <apex:column value="{!p.EE_Eligible_Population__c}"/>
            <apex:column value="{!p.Spouse_Eligible_Population__c}"/>
            <apex:column value="{!p.Dependents_Eligible_Population__c}"/>
            <apex:column value="{!p.Seniors_Eligible_Population__c}"/>
            <apex:column value="{!p.Other_Eligible_Population__c}"/>

        </apex:pageBlockTable>
           
        </apex:pageBlock>

    </apex:form>
</apex:page>

 

 

Controller

 

public class CustomOppController{

    public CustomOppController(ApexPages.StandardSetController controller) {
oppid=System.currentPageReference().getParameters().get('id');
    }

public List<Population_Assumption__c> PopulationInfo{get;set;}
//public List<Opportunity> OppsRecord{get; set;}
public String oppid{get; set;}
Public Decimal NewEEVal{get;set;}
Public Decimal NewSPVal{get;set;}
Public Decimal NewDEPVal{get;set;}
Public Decimal NewSENVal{get;set;}
Public Decimal NewOTHVal{get;set;}
public CustomOppController()

{
//oppid=System.currentPageReference().getParameters().get('id');
//OppsRecord=[Select id from Opportunity where id=:oppid];
//ApexPages.StandardSetController controller
}
//oppid=System.currentPageReference().getParameters().get('id');
public PageReference quicksave()
{
PopulationInfo=new List<Population_Assumption__c>();
   //oppid=System.currentPageReference().getParameters().get('id');
   for(Population_Assumption__c pop :[Select EE_Eligible_Population__c,Spouse_Eligible_Population__c,Dependents_Eligible_Population__c,
   Seniors_Eligible_Population__c,Other_Eligible_Population__c from Population_Assumption__c where Opportunity__c=:oppid])
    {
      IF (NewEEVal != null) {
      pop.EE_Eligible_Population__c = NewEEVal;
      }
      IF (NewSPVal != null) {
      pop.Spouse_Eligible_Population__c = NewSPVal;
      }
      IF (NewDEPVal != null) {
      pop.Dependents_Eligible_Population__c = NewDEPVal;
      }
      IF (NewSENVal != null) {
      pop.Seniors_Eligible_Population__c = NewSENVal;
      }
      IF (NewOTHVal != null) {
      pop.Other_Eligible_Population__c = NewOTHVal;
      }
     
      PopulationInfo.add(pop );
    }

update PopulationInfo;   

PageReference Newpage=new PageReference('/'+oppid);
return NewPage;

}
}