• jneilan22
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 16
    Replies

Does anyone know of a way to add a value to the Deatil Page Header?  I have a custom object with a bunch of fields that users complete.  From those fields, a score is calculated.  There are 4 sections on the custom object, each with a different score.  I want users to have the ability to expand and collapse each section as needed (which is accomplished with the Detail Page Headers), but I also want them to be able to see the value for that section, regardless of whether it is expanded or collapsed.  Is this possible and has anyone done anything similar?  Thanks.

Hello,

 

I have a custom object called Contract Summary__c that has a Master-Detail relationship with the Opportunity object.  I have a trigger that updates the some of the fields on the Opportunity with the fields from the Contract_Summary__c object after it is saved by a user.  What I need to do now to reset those fields on the Opportunity to be empty in the event that the child object is deleted.  My trigger below works fine for the insert and update portions, but does not do anything once the Contract_Summary__c record is deleted.  There are no errors, it just does not affect the Opportuinity.  Any help would be appreciated.  Thanks.

 

 

 

trigger ContractUpdates on Contract_Summary__c (before insert, before update)
{
//Update Opportunity fields from values in Contract Summary object

    list<Opportunity> opp = new list<Opportunity>();    
    set<Id> Ids = new Set <Id>();
    FOR(Contract_Summary__c con :trigger.new) {
        Ids.add(con.Related_Opportunity__c);
    }
    
    Opportunity opp1 = [SELECT Id, Start_Date__c, End_Date__c
    FROM Opportunity
    WHERE Id IN :Ids];

    if(trigger.isInsert || trigger.isUpdate)
    {      
        for(Contract_Summary__c objC : trigger.new)
        {
            opp1.Start_Date__c = objC.Current_Effective_Date__c;
            opp1.End_Date__c = objC.Current_Expiration_Date__c;
            opp1.Current_Term_Months__c = objC.Current_Term_Months__c;
            opp1.Auto_Renew__c = objC.Auto_Renew_Provision__c;
            opp1.Term_for_Convenience__c = objC.Term_for_Convenience__c;
            opp1.Portal_SLAs__c = objC.Portal_SLAs__c;
            opp1.Coaching_Performance_Guarantees__c = objC.Coaching_Performance_Guarantees__c;
            opp1.Delegated_Entity_Agreement__c = objC.Delegated_Entity_Agreement__c;
            opp1.Special_Terms__c = objC.Special_Terms__c;
            Opp.add(opp1);
        }
     }
    IF(trigger.isDelete)
    {      
        for(Contract_Summary__c objC : trigger.new)
        {

            opp1.Start_Date__c = null;
            opp1.End_Date__c = null;
            opp1.Current_Term_Months__c = null;
            opp1.Auto_Renew__c = FALSE;
            opp1.Term_for_Convenience__c = FALSE;
            opp1.Portal_SLAs__c = FALSE;
            opp1.Coaching_Performance_Guarantees__c = FALSE;
            opp1.Delegated_Entity_Agreement__c = FALSE;
            opp1.Special_Terms__c = FALSE;
            Opp.add(opp1);
        }
     }
    IF(opp.size()>0)
    Update opp;
}

Hello,

 

I have a simple trigger on the Opportunity object that fires when an Opportunity is edited and forces an edit/save on the OpportunityLineItems associated with the Opportunity.  When I try to Data Load some bulk changes, I get the following error:

 

System.LimitException: Too many SOQL queries: 101

 

I'm fairly new to Apex code.  I believe the problem is that I am running SOQL inside a FOR loop, but I'm not quite sure how to resolve it.  My trigger is below.  Any help would be appreciated.  Thanks.

 

 

trigger UpdateDeliverables on Opportunity (after insert, after update) {
   // Forces Edit/Save on Deliverables in order to fire Workflow field Update to update quantity field with Q__c value    

FOR(Opportunity opp : Trigger.new)  {

    LIST<OpportunityLineItem> oppLine = [SELECT Id
    FROM OpportunityLineItem
    WHERE OpportunityId = :opp.Id
    AND Flat_Price__c != TRUE];
    
    IF(oppLine.size() > 0)
    update oppLine;
    }

}

Hello,

 

I created a custom object called Contract_Summary__c that is the Detail record in a Master-Detail relationship with the Opportunity record.  I also created a simple custom button on the Opportunity record that creates the Contract_Summary__c record and populates a few of the fields with values from the Opportunity.  I created the trigger below to write back the Contract_Effective_Date__c and the Contract_Expiration_Date__c back to the Opportunity when the Contract_Summary__c record is created or edited.  However, when I try to save the new record I receive the following error:

 

Error: Invalid Data. Review all error messages below to correct your data. Apex trigger ContractUpdates caused an unexpected exception, contact your administrator: ContractUpdates: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0067000000MEERtAAP; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Opportunity Identifier]: [Opportunity Identifier]: Trigger.ContractUpdates: line 19, column 1

 

My trigger is below:

 

trigger ContractUpdates on Contract_Summary__c (before insert, before update) {
//Update Opportunity fields from values in Contract Summary object

System.debug('Trigger@@@@@@@@@@@@@@');

    list<Opportunity> opp = new list<Opportunity>();    

    FOR(Contract_Summary__c con :trigger.new) {
    
    Opportunity opp1 = [SELECT Id
    FROM Opportunity
    WHERE Id =:con.Related_Opportunity__c];
    System.debug('@@@@@@@@@@@@@@'+con );
    
    IF (con.Current_Effective_Date__c!=null) {
    
        opp1.Start_Date__c = con.Current_Effective_Date__c;
        opp1.End_Date__c = con.Current_Expiration_Date__c;
    update opp1;
    }
    }
    IF(opp.size()>0)
    Update opp;

}

Hello,

 

I am trying to write a trigger that will update the Opportunity Name to a standard format of "Account Name - Record Type of Opportunity (Launch Year in Opportunity)".  My trigger below returns the error "Apex trigger OpportunityName caused an unexpected exception, contact your administrator: OpportunityName: execution of BeforeInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.OpportunityName: line 7, column 1"...I am fairly new to triggers so is there something simple that I am missing?

 

 

 

trigger OpportunityName on Opportunity (before insert) {

    FOR (Opportunity opp: trigger.new) {
 
    Opportunity oppSelect = [
    SELECT RecordType.Name, Name, Launch_Year__c, Account.name, WO__c
    FROM Opportunity];
    
    IF(opp.RecordType.name=='New Business'){
          opp.Name = opp.Account.name+' - '+'New ('+opp.Launch_Year__c+')';
          }
    ELSE IF(opp.WO__c!='Yes' && opp.RecordType.name=='Upsell'){
          opp.Name = opp.Account.name+' - '+'Upsell ('+opp.Launch_Year__c+')';
          }
    ELSE IF(opp.RecordType.name=='Renewal'){
          opp.Name = opp.Account.name+' - '+'Renewal ('+opp.Launch_Year__c+')';
          }
    ELSE IF(opp.WO__c=='Yes' && opp.RecordType.name=='Upsell'){
          opp.Name = opp.Account.name+' - '+'(WO-)';
          }
          
    }

}

Hello,

 

I have a VF page with a custom controller that works great when entering values into the form fields.  However, I also need to allow users the option of removing values they have previously input.  I've worked with SFDC premier support on the code below but I have not been able to figure out how to allow a zero to be entered and replace an existing value.  In the custom controller, there is an expression to validate that the variable in the VF form is not zero because the value apparently defaults to zero.  However, this is also preventing someone from entering zero in order to remove a previous value.  Does anyone have any ideas?

 

The 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:messages />
    <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="muselectedlist" styleClass="format" value="Eligible Employee Population: ">
                <apex:inputText styleClass="box" value="{!NewEEVal}" id="muselectedlist">
                    <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="{!Ab}"/>
                <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>

 

 

The Custom Controller:

 

public class CustomOppController{

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

public List<Population_Assumption__c> PopulationInfo{get;set;}

public String oppid{get; set;}
public Integer NewEEVal{get;set;}
Public Integer NewSPVal{get;set;}
Public Integer NewDEPVal{get;set;}
Public Integer NewSENVal{get;set;}
Public Integer NewOTHVal{get;set;}

public CustomOppController()
{
}

public PageReference Ab()
{       
system.debug('####################');   
PopulationInfo=new List<Population_Assumption__c>();
   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])
    {
     system.debug('po####p:'+pop);
     system.debug('@@@@@@@@ NewEEVal :'+NewEEVal );
     system.debug('######## NewSPVal:'+NewSPVal);
     system.debug('$$$$$$$$ NewDEPVal:'+NewDEPVal);
     system.debug('%%%%%%%% NewSENVal:'+NewSENVal);
     system.debug('^^^^^^^^ NewOTHVal:'+NewOTHVal);
     system.debug('@@@@@@@@ pop.EE_Eligible_Population__c:'+pop.EE_Eligible_Population__c);
     system.debug('######## pop.Spouse_Eligible_Population__c :'+pop.Spouse_Eligible_Population__c );
     system.debug('$$$$$$$$ pop.Dependents_Eligible_Population__c:'+pop.Dependents_Eligible_Population__c);
     system.debug('%%%%%%%% pop.Seniors_Eligible_Population__c:'+pop.Seniors_Eligible_Population__c);
     system.debug('^^^^^^^^ pop.Other_Eligible_Population__c:'+pop.Other_Eligible_Population__c);
    
      IF ( NewEEVal!= null && pop.EE_Eligible_Population__c!= NewEEVal && NewEEVal!=0) {
          pop.EE_Eligible_Population__c = NewEEVal;
      }
      IF ( NewSPVal!= null && pop.Spouse_Eligible_Population__c != NewSPVal && NewSPVal!=0) {
          pop.Spouse_Eligible_Population__c = NewSPVal;
      }
      IF (NewDEPVal != null && pop.Dependents_Eligible_Population__c != NewDEPVal && NewDEPVal!=0 ) {
          pop.Dependents_Eligible_Population__c =  NewDEPVal ;
      }
      IF (NewSENVal != null && pop.Seniors_Eligible_Population__c != NewSENVal && NewSENVal!=0) {
          pop.Seniors_Eligible_Population__c =  NewSENVal ;
      }
      IF (NewOTHVal != null && pop.Other_Eligible_Population__c != NewOTHVal && NewOTHVal!=0) {
          pop.Other_Eligible_Population__c = NewOTHVal;
      }   
    PopulationInfo.add(pop);
    }

Try {
    update PopulationInfo;
    } catch(DMLException e) {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please click Cancel');
    ApexPages.addMessage(myMsg);
}  

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

 

Hello,

 

We currently use the standard Opportunity Products related list (OpportunityLineItem), but some of our products are grouped into a Basic or Premium package.  I would like to create 2 custom buttons (Basic Package & Premium Package) to replace the standard "Add Product" button that, when clicked, would pull up a list of all the products associated with each package and allow the user to enter the Price for each.  Has anyone seen anything similar to this done before and, if so, could you point me to the thread/solution where you saw it?  Thanks.

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;

}
}

 

Hello,

 

I have created 2 triggers:

 

Trigger #1 fires on the Opportunity and updates a field on a custom object called Population_Assumption__c;

 

Trigger #2 fires on the Population_Assumption__c custom object and updates a number of fields on the Opportunity object based on the values in each Population_Assumption__c record.

 

I ultimately need these 2 triggers to fire in succession, but after numerous calls to support I've realized that it cannot happen as it would be an unending loop.  However, support has told me that I can use a Visualforce page where my users can click a button to fire Trigger #2 after they update the Opportunity field manaually.

 

What I'm trying to do is to replicate the user opening each Population_Assumption__c record and saving it (no changes), which will then fire trigger #2 and update the Opportunity object.  Does anyone have any sample code that I can use as a starting point to achieve this?  I'm very new to Visualforce pages.  I've seen some code that includes an input screen, but I am just looking for something that will update all the records in the Population_Assumption__c object without requiring the user to check the ones they want to update.  Any assistance is appreciated.  Thanks!

Hello,

 

Bear with me as I am very new to Apex.  I am an Admin starting to dip my toes into the world of Apex.

 

I have created 2 triggers that work independently, but I need them to work in conjunction with one another.  I created some custom fields on the standard Opportunity object to represent population amounts.  Users can change these fields as population estimates change.  I also created a custom object <Population Assumption> that reads these fields from the Opportunity, applies some percentage assumptions, and returns an adjusted number to a field <Population> on the Population Assumption custom object.

 

The first trigger I created populates the <Population> field on the Population Assumption custom object with the adjusted populations, which I was then hoping to write back to the Opportunity and use in calculations on the Opportunity Product object.  However, I need to have 9 different fields on the Opportunity for the various adjusted populations and I only 3 roll-up summary fields left.

 

The 2nd trigger I created writes the value of the <Population> field referenced above to the Opportunity, but it only works if you edit the custom object records directly.

 

What I need to have is for the 1st trigger work as it does to update the <Population> field on the Population Assumption custom object, but then have the 2nd trigger recognize it as an update and fire to update the Opportunity.

 

Does anyone have sample code that would do this or at least know if it is possible?  I really just need to mimic an update to the custom objects as the trigger update is not recognized by the After Update function.  Thanks.

Hello,

 

I have a custom object called Contract Summary__c that has a Master-Detail relationship with the Opportunity object.  I have a trigger that updates the some of the fields on the Opportunity with the fields from the Contract_Summary__c object after it is saved by a user.  What I need to do now to reset those fields on the Opportunity to be empty in the event that the child object is deleted.  My trigger below works fine for the insert and update portions, but does not do anything once the Contract_Summary__c record is deleted.  There are no errors, it just does not affect the Opportuinity.  Any help would be appreciated.  Thanks.

 

 

 

trigger ContractUpdates on Contract_Summary__c (before insert, before update)
{
//Update Opportunity fields from values in Contract Summary object

    list<Opportunity> opp = new list<Opportunity>();    
    set<Id> Ids = new Set <Id>();
    FOR(Contract_Summary__c con :trigger.new) {
        Ids.add(con.Related_Opportunity__c);
    }
    
    Opportunity opp1 = [SELECT Id, Start_Date__c, End_Date__c
    FROM Opportunity
    WHERE Id IN :Ids];

    if(trigger.isInsert || trigger.isUpdate)
    {      
        for(Contract_Summary__c objC : trigger.new)
        {
            opp1.Start_Date__c = objC.Current_Effective_Date__c;
            opp1.End_Date__c = objC.Current_Expiration_Date__c;
            opp1.Current_Term_Months__c = objC.Current_Term_Months__c;
            opp1.Auto_Renew__c = objC.Auto_Renew_Provision__c;
            opp1.Term_for_Convenience__c = objC.Term_for_Convenience__c;
            opp1.Portal_SLAs__c = objC.Portal_SLAs__c;
            opp1.Coaching_Performance_Guarantees__c = objC.Coaching_Performance_Guarantees__c;
            opp1.Delegated_Entity_Agreement__c = objC.Delegated_Entity_Agreement__c;
            opp1.Special_Terms__c = objC.Special_Terms__c;
            Opp.add(opp1);
        }
     }
    IF(trigger.isDelete)
    {      
        for(Contract_Summary__c objC : trigger.new)
        {

            opp1.Start_Date__c = null;
            opp1.End_Date__c = null;
            opp1.Current_Term_Months__c = null;
            opp1.Auto_Renew__c = FALSE;
            opp1.Term_for_Convenience__c = FALSE;
            opp1.Portal_SLAs__c = FALSE;
            opp1.Coaching_Performance_Guarantees__c = FALSE;
            opp1.Delegated_Entity_Agreement__c = FALSE;
            opp1.Special_Terms__c = FALSE;
            Opp.add(opp1);
        }
     }
    IF(opp.size()>0)
    Update opp;
}

Hello,

 

I have a simple trigger on the Opportunity object that fires when an Opportunity is edited and forces an edit/save on the OpportunityLineItems associated with the Opportunity.  When I try to Data Load some bulk changes, I get the following error:

 

System.LimitException: Too many SOQL queries: 101

 

I'm fairly new to Apex code.  I believe the problem is that I am running SOQL inside a FOR loop, but I'm not quite sure how to resolve it.  My trigger is below.  Any help would be appreciated.  Thanks.

 

 

trigger UpdateDeliverables on Opportunity (after insert, after update) {
   // Forces Edit/Save on Deliverables in order to fire Workflow field Update to update quantity field with Q__c value    

FOR(Opportunity opp : Trigger.new)  {

    LIST<OpportunityLineItem> oppLine = [SELECT Id
    FROM OpportunityLineItem
    WHERE OpportunityId = :opp.Id
    AND Flat_Price__c != TRUE];
    
    IF(oppLine.size() > 0)
    update oppLine;
    }

}

Hello,

 

I created a custom object called Contract_Summary__c that is the Detail record in a Master-Detail relationship with the Opportunity record.  I also created a simple custom button on the Opportunity record that creates the Contract_Summary__c record and populates a few of the fields with values from the Opportunity.  I created the trigger below to write back the Contract_Effective_Date__c and the Contract_Expiration_Date__c back to the Opportunity when the Contract_Summary__c record is created or edited.  However, when I try to save the new record I receive the following error:

 

Error: Invalid Data. Review all error messages below to correct your data. Apex trigger ContractUpdates caused an unexpected exception, contact your administrator: ContractUpdates: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0067000000MEERtAAP; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Opportunity Identifier]: [Opportunity Identifier]: Trigger.ContractUpdates: line 19, column 1

 

My trigger is below:

 

trigger ContractUpdates on Contract_Summary__c (before insert, before update) {
//Update Opportunity fields from values in Contract Summary object

System.debug('Trigger@@@@@@@@@@@@@@');

    list<Opportunity> opp = new list<Opportunity>();    

    FOR(Contract_Summary__c con :trigger.new) {
    
    Opportunity opp1 = [SELECT Id
    FROM Opportunity
    WHERE Id =:con.Related_Opportunity__c];
    System.debug('@@@@@@@@@@@@@@'+con );
    
    IF (con.Current_Effective_Date__c!=null) {
    
        opp1.Start_Date__c = con.Current_Effective_Date__c;
        opp1.End_Date__c = con.Current_Expiration_Date__c;
    update opp1;
    }
    }
    IF(opp.size()>0)
    Update opp;

}

Hello,

 

I am trying to write a trigger that will update the Opportunity Name to a standard format of "Account Name - Record Type of Opportunity (Launch Year in Opportunity)".  My trigger below returns the error "Apex trigger OpportunityName caused an unexpected exception, contact your administrator: OpportunityName: execution of BeforeInsert caused by: System.QueryException: List has more than 1 row for assignment to SObject: Trigger.OpportunityName: line 7, column 1"...I am fairly new to triggers so is there something simple that I am missing?

 

 

 

trigger OpportunityName on Opportunity (before insert) {

    FOR (Opportunity opp: trigger.new) {
 
    Opportunity oppSelect = [
    SELECT RecordType.Name, Name, Launch_Year__c, Account.name, WO__c
    FROM Opportunity];
    
    IF(opp.RecordType.name=='New Business'){
          opp.Name = opp.Account.name+' - '+'New ('+opp.Launch_Year__c+')';
          }
    ELSE IF(opp.WO__c!='Yes' && opp.RecordType.name=='Upsell'){
          opp.Name = opp.Account.name+' - '+'Upsell ('+opp.Launch_Year__c+')';
          }
    ELSE IF(opp.RecordType.name=='Renewal'){
          opp.Name = opp.Account.name+' - '+'Renewal ('+opp.Launch_Year__c+')';
          }
    ELSE IF(opp.WO__c=='Yes' && opp.RecordType.name=='Upsell'){
          opp.Name = opp.Account.name+' - '+'(WO-)';
          }
          
    }

}

Hello,

 

I have a VF page with a custom controller that works great when entering values into the form fields.  However, I also need to allow users the option of removing values they have previously input.  I've worked with SFDC premier support on the code below but I have not been able to figure out how to allow a zero to be entered and replace an existing value.  In the custom controller, there is an expression to validate that the variable in the VF form is not zero because the value apparently defaults to zero.  However, this is also preventing someone from entering zero in order to remove a previous value.  Does anyone have any ideas?

 

The 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:messages />
    <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="muselectedlist" styleClass="format" value="Eligible Employee Population: ">
                <apex:inputText styleClass="box" value="{!NewEEVal}" id="muselectedlist">
                    <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="{!Ab}"/>
                <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>

 

 

The Custom Controller:

 

public class CustomOppController{

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

public List<Population_Assumption__c> PopulationInfo{get;set;}

public String oppid{get; set;}
public Integer NewEEVal{get;set;}
Public Integer NewSPVal{get;set;}
Public Integer NewDEPVal{get;set;}
Public Integer NewSENVal{get;set;}
Public Integer NewOTHVal{get;set;}

public CustomOppController()
{
}

public PageReference Ab()
{       
system.debug('####################');   
PopulationInfo=new List<Population_Assumption__c>();
   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])
    {
     system.debug('po####p:'+pop);
     system.debug('@@@@@@@@ NewEEVal :'+NewEEVal );
     system.debug('######## NewSPVal:'+NewSPVal);
     system.debug('$$$$$$$$ NewDEPVal:'+NewDEPVal);
     system.debug('%%%%%%%% NewSENVal:'+NewSENVal);
     system.debug('^^^^^^^^ NewOTHVal:'+NewOTHVal);
     system.debug('@@@@@@@@ pop.EE_Eligible_Population__c:'+pop.EE_Eligible_Population__c);
     system.debug('######## pop.Spouse_Eligible_Population__c :'+pop.Spouse_Eligible_Population__c );
     system.debug('$$$$$$$$ pop.Dependents_Eligible_Population__c:'+pop.Dependents_Eligible_Population__c);
     system.debug('%%%%%%%% pop.Seniors_Eligible_Population__c:'+pop.Seniors_Eligible_Population__c);
     system.debug('^^^^^^^^ pop.Other_Eligible_Population__c:'+pop.Other_Eligible_Population__c);
    
      IF ( NewEEVal!= null && pop.EE_Eligible_Population__c!= NewEEVal && NewEEVal!=0) {
          pop.EE_Eligible_Population__c = NewEEVal;
      }
      IF ( NewSPVal!= null && pop.Spouse_Eligible_Population__c != NewSPVal && NewSPVal!=0) {
          pop.Spouse_Eligible_Population__c = NewSPVal;
      }
      IF (NewDEPVal != null && pop.Dependents_Eligible_Population__c != NewDEPVal && NewDEPVal!=0 ) {
          pop.Dependents_Eligible_Population__c =  NewDEPVal ;
      }
      IF (NewSENVal != null && pop.Seniors_Eligible_Population__c != NewSENVal && NewSENVal!=0) {
          pop.Seniors_Eligible_Population__c =  NewSENVal ;
      }
      IF (NewOTHVal != null && pop.Other_Eligible_Population__c != NewOTHVal && NewOTHVal!=0) {
          pop.Other_Eligible_Population__c = NewOTHVal;
      }   
    PopulationInfo.add(pop);
    }

Try {
    update PopulationInfo;
    } catch(DMLException e) {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please click Cancel');
    ApexPages.addMessage(myMsg);
}  

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

 

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;

}
}

 

Hello,

 

Bear with me as I am very new to Apex.  I am an Admin starting to dip my toes into the world of Apex.

 

I have created 2 triggers that work independently, but I need them to work in conjunction with one another.  I created some custom fields on the standard Opportunity object to represent population amounts.  Users can change these fields as population estimates change.  I also created a custom object <Population Assumption> that reads these fields from the Opportunity, applies some percentage assumptions, and returns an adjusted number to a field <Population> on the Population Assumption custom object.

 

The first trigger I created populates the <Population> field on the Population Assumption custom object with the adjusted populations, which I was then hoping to write back to the Opportunity and use in calculations on the Opportunity Product object.  However, I need to have 9 different fields on the Opportunity for the various adjusted populations and I only 3 roll-up summary fields left.

 

The 2nd trigger I created writes the value of the <Population> field referenced above to the Opportunity, but it only works if you edit the custom object records directly.

 

What I need to have is for the 1st trigger work as it does to update the <Population> field on the Population Assumption custom object, but then have the 2nd trigger recognize it as an update and fire to update the Opportunity.

 

Does anyone have sample code that would do this or at least know if it is possible?  I really just need to mimic an update to the custom objects as the trigger update is not recognized by the After Update function.  Thanks.