• Lisa Horne
  • NEWBIE
  • 65 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 13
    Replies

I have this apex trigger but getting the following error when trying to delete contract product from an opportunity.  Could someone please let me know what I need to fix so I can delete contract products?

trigger Contract_Product_Delete_Update_Accounts_and_Contracts on Contract_Product__c (after delete) 
{  
  system.debug('DELETE TRIGGER FIRSTRUN VARIABLE: ' + Account_Contract_Update_Class.FirstRun);
  if(Account_Contract_Update_Class.FirstRun == true)
  {
    Account_Contract_Update_Class.FirstRun = false;
    system.debug('CONTRACT PRODUCT DELETE TRIGGER!!!!');
    String ObjectDMLType ='ContractProductDelete';
    set<ID> TheseAccountIDs = new set<id>(); //Set of Account IDs that have Contract Products. 
                        //These Accounts Need to be updated by checking All their active Contract Products
    set<id> TheseContractIDs = new set<id>();                      
    list<string> Products = new list<string>();
    for(Contract_Product__c cp : trigger.old)
    {
      TheseAccountIds.add(cp.Account__c);  
      TheseContractIds.add(cp.Contract__c);  
      Products.add(string.valueof(cp.Product_Family__c));
    }    
    system.debug('Number of Products removed: ' + trigger.old.size());  
    system.debug('These are the accounts that will be updated: ' + TheseAccountIds);
    system.debug('These are Products being deleted: ' + Products);    
    
    //Update the Contract
    Account_Contract_Update_Class.UpdateContracts(TheseContractIDs, ObjectDMLType);  
    //Update the Account
    Account_Contract_Update_Class.UpdateAccounts(TheseAccountIDs, ObjectDMLType);
  }
//last brackett
}


 

ERROR I am getting:
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contract_Product_Delete_Update_Accounts_and_Contracts caused an unexpected exception, contact your administrator: Contract_Product_Delete_Update_Accounts_and_Contracts: execution of AfterDelete caused by: System.QueryException: No such column 'BillingAddress' on entity 'Contract'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.: Class.Account_Contract_Update_Class.UpdateContracts: line 238, column 1". 

Click here to return to the previous page.
 

I created a VF page for a custom object and would like to have the column header "Certification Year" sorted by default in decending order.

Is there an easy way to do this without a controller? I'm new to coding and am not familiar with this. Or can someone help me with getting it done?

This is the code I have for the visualforce page:


<apex:page standardController="Account">
   
      You are viewing the {!account.name} account.

      <apex:pageBlock title="ONS's">

      <apex:pageBlockTable value="{!account.ONC_s__r}" var="onc">

         <apex:column value="{!onc.Name}"/>
         <apex:column value="{!onc.Owner.name}"/>
         <apex:column value="{!onc.Certification_Year__c}"  />
         <apex:column value="{!onc.Practice_Setting__c}"/>
         

      </apex:pageBlockTable>

   </apex:pageBlock>

</apex:page>
I want to create a VF page on the Account that will display the related list of the HL Contracts records that have a look up to the Account.

I have the following but it gives me this error:  Content cannot be displayed: 'HLContracts__r' is not a valid child relationship name for entity Account

This is the code I have:

<apex:page standardController="Account">
<apex:relatedList list="HLContracts__r" />
</apex:page>


 
I am getting this error on a legacy trigger.  Could someone please help with this one?

Contract_Update_Before_After_Update: execution of AfterUpdate

caused by: System.AsyncException: Future method cannot be called from a future or batch method: Account_Contract_Update_Class.UpdateAccounts(SET<Id>, String)

Trigger.Contract_Update_Before_After_Update: line 147, column 1 : CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY ()



trigger Contract_Update_Before_After_Update on Contract (after update, before update) 
{
  system.debug('Update TRIGGER FIRSTRUN VARIABLE: ' + Account_Contract_Update_Class.FirstRun);
  list<Contract> TheseContracts = new list<Contract>();
  if(Global_Apex_Calls_Class.FireTriggers == true &&  Global_Apex_Calls_Class.FireGeoCode == true)
  {
    //Query all possible Product Families from Products and put into list
    //Important Product Families should match the API name of Product in Amount fields
      //Get describe of all possible picklist values
    list<Schema.PicklistEntry> ProductFamily_Values = Product2.Family.getDescribe().getPickListValues();
    list<String> ProductFamilies = new list<string>();
    //Loop through all Product Family values from picklist. Get Label of picklist from each value and add to list of ProductFamilies
    string FamilyName = null;
    for(integer i = 0; i<ProductFamily_Values.size(); i++)
    {
      FamilyName =string.valueof(ProductFamily_Values[i].getLabel());
      FamilyName = FamilyName.Replace(' ','_');
      ProductFamilies.add(FamilyName);
    }  
    
    if(Account_Contract_Update_Class.FirstRun == true)
    {
      //Account_Contract_Update_Class.FirstRun = false;
      system.debug('Trigger Is Update: ' + Trigger.isUpdate);
      system.debug('Trigger is Insert: ' + Trigger.isInsert);
      if(Trigger.isInsert == false)
      {
        system.debug('CONTRACT TRIGGER ACTIVATED!');
        String ObjectDMLType ='ContractBefore';
        //Create Set of IDs for Account and Contract Objects on the updated and inserted Contract Products
        set<ID> TheseContractIDs = new set <ID>(); //set of Contract IDs for all Contract Products. 
                              //These Contracts will need to be updated by checking all their Contract Products
        set<ID> TheseAccountIDs = new set<id>(); //Set of Account IDs that have Contract Products. 
                            //These Accounts Need to be updated by checking All their active Contract Products
        for(Contract c : Trigger.New)
        {
          //Add This Contract ID to set TheseContractIDs
          TheseContractIDs.add(c.id);
          //Add This Account ID to set TheseAccountIDs
          TheseAccountIDs.add(c.AccountID); 
          TheseContracts.add(c);
        }
        //THIS IS A TEST TO UPDATE THE CONTRACTS ONLY 
        system.debug('CONTRACTS SENT TO CLASS: ' + TheseContractIds);
      
        if(Trigger.isBefore)
        {  
          system.debug('Contract Update Trigger IS BEFORE!!');
          list<Contract> FromClass = new list<Contract>();
          //FromClass = Account_Contract_Update_Class.UpdateContracts(TheseContractIDs, ObjectDMLType);  
          Account_Contract_Update_Class.UpdateContracts_Trigger(TheseContracts, ObjectDMLType);
          //system.debug('RETURN FROM CLASS: ' + FromClass);
          system.debug('RETURN FROM CLASS: ' + FromClass);
          //system.assert(false,'After class!:  '+ FromClass.size());
        }
/*
          if(FromClass != null && FromClass.size() > 0)
          {        
  
            map<id, Contract> mFromClass = new map<id,Contract>();
            for(Contract c : FromClass)
            {
              mFromClass.put(c.id,c);
            }
            
            Contract cFromClass = null;
  
            //Variables for Contract Loop
            String RecurringField = '_Total_Recuring_Amount__c';
            string NonRecurringField = '_Total_Non_Recurring_Amount__c';
  
            Object O = null; //Variable of field object that we can get the value of field name
            //Build map of all fields on Contract
            Map<String, Schema.SObjectField> mFields = new Contract().getSobjectType().getDescribe().fields.getMap();    
            //Dynamic Apex variables. 
            sObject delegate; //Contract active in loop
            sObject FromDelegate;
            Schema.SobjectField f; //Field in contract being updated
            string FieldName = null; //Field API name. Used to get Field from mFields (Field Map)
      
            for(integer i=0;i<Trigger.new.size();i++)
            {
              RecurringField = '_Total_Recurring_Amount__c'; //Standard Ending. FieldName format is *Product*_Total_Recurring_Amount__c
              NonRecurringField = '_Total_Non_Recurring_Amount__c';//Standard Ending. FieldName format is *Product*_Total_Non_Recurring_Amount__c
              cFromClass = null;
              cFromClass = mFromClass.get(Trigger.new[i].id);      
              //for(integer v=0; i<FromClass.size();v++)
              //{
                //if(Trigger.new[i].id == FromClass[v].id)
                if(cFromClass != null)
                {
                  system.debug('Contract From Class - S797 Total Recurring Amount: ' + cFromClass.Simplifi_797_Total_Recurring_Amount__c);  
                  system.debug('Contract From Class - S797  Total Recurring Amount: ' +Trigger.new[i].Simplifi_797_Total_Recurring_Amount__c);              
                  FromDelegate = cFromClass;
                  delegate = Trigger.new[i]; //Set the current contract in loop to the delegate sObject
                  //Loop through Products
                  for(integer p=0; p<ProductFamilies.size(); p++)
                  {
                    //Default Recurring Field
                    FieldName = ProductFamilies[p] + RecurringField; //Build API name for field
                    f = mFields.get(FieldName); //Get the field from map of fields based on API Name
                    system.debug('Default field: ' + FieldName);
                    //Check to see if F is null. Null means field does not exist
                    if(f != null)
                    {
                      O = FromDelegate.get(f);
                      delegate.put(f, O); //Set the value of the field to 0
                    }
                    //Default Non Recurring Field
                    FieldName = ProductFamilies[p] + NonRecurringField; //Build API name for field
                    f = mFields.get(FieldName); //Get the field from map of fields based on API Name
                    //Check to see if F is null. Null means field does not exist
                    if(f != null)
                    {
                      O = FromDelegate.get(f);
                      delegate.put(f, O); //Set the value of the field to 0
                    }        
                  //End Prodct Family Loop
                  }                
                //End Trigger and Class Match  
                }
              //End FromClass Loop  
              //}
            system.debug('Yearly Revenue: ' + Trigger.new[i].yearly_revenue__c);
            system.debug('Products on Contract: ' + Trigger.new[i].Products_included_in_Contract__c);  
            //system.assert(Trigger.new[i].Products_included_in_Contract__c != '', 'PRODUCT LIST NOT UPDATED!');
            //system.assert(Trigger.new[i].simplifi_797_Amount__c > 0, 'Product Amount Not Updated!');          
            //end Trigger Loop          
            }
          //end If Existing FromClass                
          }  
        }  
*/            
        if(Trigger.isAfter)
        {  
          system.debug('Contract Update Trigger IS AFTER!!');
          /*Information to update Accounts */
          list<Contract_Product__c> TheseProducts = [Select c.Total_Price__c, c.Sale_Type__c, c.Quantity__c, c.Product_Family__c, 
            c.New_Client__c, c.Name, c.Id, c.Exception__c, c.Discount__c, c.Contract__c, c.Contract_Product__c, 
            c.Annual_Price__c, c.Annual_List_Price__c, c.Account__c From Contract_Product__c c where c.Contract__c in :TheseContractIds];
          if(TheseProducts != Null && TheseProducts.size() >0)
          {
            for(Contract_Product__c cp : TheseProducts)
            {
              TheseAccountIds.add(cp.Account__c);
            }
            Account_Contract_Update_Class.UpdateAccounts(TheseAccountIDs, ObjectDMLType);
          }
        }  
      }
    //FirstRun IF statement
    }
  //Trigger global test
  }
//last brackett
}
Trying to create a controller that references a custom object Called Parent Implementation.  And getting an error can someone please help?

[Error] Error: Compile Error: Variable does not exist: Parent_Implementation__c.Clarizen_Project__c at line 16 column 43

public class ParentImplementationClarizenController {

     private final Parent_Implementation__c parentimplementation;
    private final clzV5__Clarizen_Project__c project;
    private boolean error = false;
    private String errorText = '';
    private String html = '';
    private String baseUrl;
    private boolean projectExists = false;
    private final Account account;
    private final List<clzV5__Clarizen_Milestone__c> milestones;
    
     public ParentImplementationClarizenController(ApexPages.StandardController stdController) {
        System.debug('Accessing constructor for ParentImplementationClarizenController');
        this.implementation = (Parent_Implementation__c) stdController.getRecord();
        System.debug('Clarizen id is: ' + Parent_Implementation__c.Clarizen_Project__c);
 
I have the following trigger  and I am getting this error on the Test Class.  Could someone point out what I am doing wrong on the test class?

API Name
Type
Line
Column
Problem
TestCreateTaskOnInsertWebToLead.TestCreateTaskOnInsertWebToLead() Class 35 1 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []", Failure Stack Trace: "Class.TestCreateTaskOnInsertWebToLead.TestCreateTaskOnInsertWebToLead: line 35, column 1"

Trigger
User-added image

Class
User-added image
The Contact Role object cannot have fields added to it.  In order to get around this I have created a custom object with an Object Name= OpportunityContactRoles and gave it a child relationship to the opportunity object.  The custom object has the two fields that are on the Contact Role object, ContactID and Parts (same as Role), but also has additional fields on it.

What I would like to have happen is every time a Contact name and Parts has been entered into the custom object and saved, a new  standard Contact Role is automatically created on the opportunity with the same Contact name and Role (Parts). 

Could someone confirm that this code will do that and also assist in creating a Class for it?




trigger New_Contact_Role_to_Standard on Contact_Role__c {
List<OpportunityContactRole> lstOCRs = new List<OpportunityContactRole>();
for (Contact_Role__c cr : trigger.new) {
if ((cr.Contact_Name__c != null && cr.Parts__c != null) &&
     (trigger.isInsert || (trigger.isUpdate && trigger.oldmap.get(cr.Id).Contact_Name__c == null || trigger.oldmap.get(cr.Id).Parts__c == null))) {
OpportunityContactRole ocr = new OpportunityContactRole();
ocr.OpportunityId = cr.Opportunity__c;
ocr.ContactID       = cr.Contact_Name__c;
ocr.Role                = cr.Parts__c;

lstOCRs.add(ocr);
}
}
update lstOCRs;

}
The Contact Role object can not have fields added to it.  In order to get around this I have created a custom object  with an Object Name= OpportunityContactRoles and gave it a child relationship to the opportunity object.  The custom object has the two fields that are on the Contact Role object, ContactID and Object Name Parts (same as Role), but also has additional fields on it.

What I would like to have happen is every time a Contact name and Parts has been entered into the custom object and saved, a new  standard Contact Role is automatically created on the opportunity with the same Contact name and Role (Parts).  Can anyone help me with a trigger and class for this?  So far I have this but I know it's not even close.


trigger new_Contact_Role_to_Standard on Contact Role
{
   for(Contact Role c : Trigger.New)
   {
        OpportunityContactRole o = new OpportunityContactRole;
        o.ContactId = set the contact id here;
        o.OpportunityId = set the Opportunity id here;
        insert o;
   }
}
I need some assitance with creating a Trigger that creates a task from a lead record that has text in the Lead Web Comment Field to create a task for the Lead owner, with priority of Normal, Subject of Text "Lead Web Comment", Status of Lead Web Comment.

I have this trigger started but don't know exactly how to have all the fields populated with the above requirements.

Could someone please help?


trigger Lead_After_Insert on Lead (after insert)

{
  list<Task> lNewTasks = new list<Task>();

  for(integer i=0; i<trigger.new.size(); i++)

  {

     lNewTasks.add(MyTask = new Task(

       Subject = 'Lead Web Comment',

       WhoID = trigger.new[i].id

       *Other Task Fields Here*

     );

   }

   insert lNewTasks;

}
Would it be possible to create a apex trigger from a child object to another child object?  or does it have to be parent to child or child to parent?
Hello!

I am pretty new to Visual Force and Apex but I am needing to create an VisualForce page, appex code and custom button to be able to customze the lead convert process.  Could someone please help?

The following are my requirments:

The ‘Create an opportunity’ at the time of conversion checkbox must be read only.
The ‘Create an opportunity’ at the time of conversion checkbox must be set to ‘T’ (i.e. must be checked), if the Lead Status is not equal to ‘Closed – Current Opportunity’.
The ‘Create an opportunity’ at the time of conversion checkbox must be set to ‘F’ (i.e. not checked), if the Lead Status is equal to ‘Closed – Current Opportunity’.


Thanks,
Lisa

I have this apex trigger but getting the following error when trying to delete contract product from an opportunity.  Could someone please let me know what I need to fix so I can delete contract products?

trigger Contract_Product_Delete_Update_Accounts_and_Contracts on Contract_Product__c (after delete) 
{  
  system.debug('DELETE TRIGGER FIRSTRUN VARIABLE: ' + Account_Contract_Update_Class.FirstRun);
  if(Account_Contract_Update_Class.FirstRun == true)
  {
    Account_Contract_Update_Class.FirstRun = false;
    system.debug('CONTRACT PRODUCT DELETE TRIGGER!!!!');
    String ObjectDMLType ='ContractProductDelete';
    set<ID> TheseAccountIDs = new set<id>(); //Set of Account IDs that have Contract Products. 
                        //These Accounts Need to be updated by checking All their active Contract Products
    set<id> TheseContractIDs = new set<id>();                      
    list<string> Products = new list<string>();
    for(Contract_Product__c cp : trigger.old)
    {
      TheseAccountIds.add(cp.Account__c);  
      TheseContractIds.add(cp.Contract__c);  
      Products.add(string.valueof(cp.Product_Family__c));
    }    
    system.debug('Number of Products removed: ' + trigger.old.size());  
    system.debug('These are the accounts that will be updated: ' + TheseAccountIds);
    system.debug('These are Products being deleted: ' + Products);    
    
    //Update the Contract
    Account_Contract_Update_Class.UpdateContracts(TheseContractIDs, ObjectDMLType);  
    //Update the Account
    Account_Contract_Update_Class.UpdateAccounts(TheseAccountIDs, ObjectDMLType);
  }
//last brackett
}


 

ERROR I am getting:
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contract_Product_Delete_Update_Accounts_and_Contracts caused an unexpected exception, contact your administrator: Contract_Product_Delete_Update_Accounts_and_Contracts: execution of AfterDelete caused by: System.QueryException: No such column 'BillingAddress' on entity 'Contract'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.: Class.Account_Contract_Update_Class.UpdateContracts: line 238, column 1". 

Click here to return to the previous page.
 

I created a VF page for a custom object and would like to have the column header "Certification Year" sorted by default in decending order.

Is there an easy way to do this without a controller? I'm new to coding and am not familiar with this. Or can someone help me with getting it done?

This is the code I have for the visualforce page:


<apex:page standardController="Account">
   
      You are viewing the {!account.name} account.

      <apex:pageBlock title="ONS's">

      <apex:pageBlockTable value="{!account.ONC_s__r}" var="onc">

         <apex:column value="{!onc.Name}"/>
         <apex:column value="{!onc.Owner.name}"/>
         <apex:column value="{!onc.Certification_Year__c}"  />
         <apex:column value="{!onc.Practice_Setting__c}"/>
         

      </apex:pageBlockTable>

   </apex:pageBlock>

</apex:page>
I want to create a VF page on the Account that will display the related list of the HL Contracts records that have a look up to the Account.

I have the following but it gives me this error:  Content cannot be displayed: 'HLContracts__r' is not a valid child relationship name for entity Account

This is the code I have:

<apex:page standardController="Account">
<apex:relatedList list="HLContracts__r" />
</apex:page>


 
I have the following trigger  and I am getting this error on the Test Class.  Could someone point out what I am doing wrong on the test class?

API Name
Type
Line
Column
Problem
TestCreateTaskOnInsertWebToLead.TestCreateTaskOnInsertWebToLead() Class 35 1 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []", Failure Stack Trace: "Class.TestCreateTaskOnInsertWebToLead.TestCreateTaskOnInsertWebToLead: line 35, column 1"

Trigger
User-added image

Class
User-added image
The Contact Role object can not have fields added to it.  In order to get around this I have created a custom object  with an Object Name= OpportunityContactRoles and gave it a child relationship to the opportunity object.  The custom object has the two fields that are on the Contact Role object, ContactID and Object Name Parts (same as Role), but also has additional fields on it.

What I would like to have happen is every time a Contact name and Parts has been entered into the custom object and saved, a new  standard Contact Role is automatically created on the opportunity with the same Contact name and Role (Parts).  Can anyone help me with a trigger and class for this?  So far I have this but I know it's not even close.


trigger new_Contact_Role_to_Standard on Contact Role
{
   for(Contact Role c : Trigger.New)
   {
        OpportunityContactRole o = new OpportunityContactRole;
        o.ContactId = set the contact id here;
        o.OpportunityId = set the Opportunity id here;
        insert o;
   }
}
I need some assitance with creating a Trigger that creates a task from a lead record that has text in the Lead Web Comment Field to create a task for the Lead owner, with priority of Normal, Subject of Text "Lead Web Comment", Status of Lead Web Comment.

I have this trigger started but don't know exactly how to have all the fields populated with the above requirements.

Could someone please help?


trigger Lead_After_Insert on Lead (after insert)

{
  list<Task> lNewTasks = new list<Task>();

  for(integer i=0; i<trigger.new.size(); i++)

  {

     lNewTasks.add(MyTask = new Task(

       Subject = 'Lead Web Comment',

       WhoID = trigger.new[i].id

       *Other Task Fields Here*

     );

   }

   insert lNewTasks;

}

As you know, the Contact Role object can not have fields added to it.  In order to get around this I have created a custom object called Contact Roles and gave it a child relationship to the opportunity object.  The custom object has the same two fields that are on the Contact Role object, ContactID and Role, but also has additional fields on it.

What I would like to have happen is every time a Contact name and Role has been entered into the custom object and saved, a new Contact Role is automatically created on the opportunity with the same Contact name and Role.  Does anyone know of a solution for this?

 

Regards,

Andrew