• AprilV
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies

Hello,

 

I am trying to create a trigger on the Contract record that will update 2 email fields on the contract record from fields on the releated opportunity record.

 

Here is my code:

trigger UpdateContractEmails on Contract (before insert, before update, after insert, after update){ 

for (Contract c : trigger.new){

   Opportunity opp = [SELECT Id FROM Opportunity WHERE Id = :c.Opportunity__c]; 
   
c.Account_Manager_Email__c = opp.Account_Manager_Email__c;
c.Account_Executive_Email__c = opp.Account_Executive_Email__c;
update c;

}
}

 

And here is the error I am getting on the record when I am trying to save:

 

Apex trigger UpdateContractEmails caused an unexpected exception, contact your administrator: UpdateContractEmails: execution of BeforeInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Account_Manager_Email__c: Trigger.UpdateContractEmails: line 7, column 30

 

Any ideas on what changes I need to make to the code to make this work? I would use a formula field to port this info over, but I need these fileds to be filed type email address so I can use them in an email alert.

 

Thanks!

  • December 02, 2011
  • Like
  • 0

Is there a way to create an APEX case Trigger that will automatically assign case team members based on the user who created the case and/or based on a user in a relative lookup field?

 

If so, would anybody be able to offer me some sample code that could help me jump start my trigger attempt?

  • September 16, 2011
  • Like
  • 0

I would like to update the Account Name field on the case based on what was input for the case's Opportunity lookup field (custom lookup field, field name is Opportunity__c). I would like to update the Account Name field on the case to the selected Opportunity's Account.

I am not familiar enough with apex triggers to get this to work. If anyone can offer me some sample code to get me started, I would greatly appreciate it.

  • April 06, 2011
  • Like
  • 0

I am trying to create a Trigger on the CaseComments object that will set the default value of the "Public" checkbox to true when a new case comment is created. I have never created any apex code before, but this is what I came up with:

 

 

trigger PublicComment on CaseComment (before insert, before update) {
CaseComment[] checkCaseComment = Trigger.new; for(CaseComment t : checkCaseComment){ t.IsPublished = true;}
}

 

 

I am testing this in my Sandbox and it seems to be marking the case comment as "Public" after the new case comment is saved. However, I want my trigger to make it so the box is already checked by default before the case is saved.

 

Any suggestions?

  • February 24, 2011
  • Like
  • 0

I would like to update the Account Name field on the case based on what was input for the case's Opportunity lookup field (custom lookup field, field name is Opportunity__c). I would like to update the Account Name field on the case to the selected Opportunity's Account.

I am not familiar enough with apex triggers to get this to work. If anyone can offer me some sample code to get me started, I would greatly appreciate it.

  • April 06, 2011
  • Like
  • 0

I am trying to create a Trigger on the CaseComments object that will set the default value of the "Public" checkbox to true when a new case comment is created. I have never created any apex code before, but this is what I came up with:

 

 

trigger PublicComment on CaseComment (before insert, before update) {
CaseComment[] checkCaseComment = Trigger.new; for(CaseComment t : checkCaseComment){ t.IsPublished = true;}
}

 

 

I am testing this in my Sandbox and it seems to be marking the case comment as "Public" after the new case comment is saved. However, I want my trigger to make it so the box is already checked by default before the case is saved.

 

Any suggestions?

  • February 24, 2011
  • Like
  • 0