• David Smith
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi all,

 

With the help of users from this board I was able to write and implement triggers in my sandbox environment, the code for which is below. However, when I tried to move it to live it fell over, telling me I needed 75% code covereage. 

 

Could someone give me some insight into writing this test class? As far as I know it's about testing your interactions with records, but I'm not sure how to go about doing that.

 

 

}

trigger Contact_Update_SCIWorkflow on Event (before update, before insert)
{   
List<Contact> conForUpdate = new List<Contact>();       
for(Event e : Trigger.New)
    {

        if(e.whoid != null)
        {
            if(e.Consultative_Selling_Sci_Work_Flows__c == TRUE)
            {
                If(Trigger.IsInsert || (Trigger.IsUpdate && (Trigger.oldMap.get(e.Id).Consultative_Selling_Sci_Work_Flows__c !=Trigger.newMap.get(e.Id).Consultative_Selling_Sci_Work_Flows__c)
                                        )
                   )
                                {           
                                conForUpdate.add
                                    (
                                    new Contact
                                        (
                                        Id = e.WhoId,


                                        Consultative_Selling_Sci__c = TRUE,
                                        Consultative_Selling_SCI_Last_Pres_Date__c = e.Startdatetime


                                        )
                                    );       
                                }   
}       
 
 
 
 
if(conForUpdate != NULL && conForUpdate.size() > 0)
{update conForUpdate;}    

        }
    }

Hi everyone,

 

I'm new to Apex coding, so please forgive me if this question is amazingly basic.

 

I'm trying to build a trigger that fires when a contact record is edited. It should look at the value of a checkbox on the contact and use that to update the value of a checkbox on the contacts Account. 

 

This is what I have currently:

 

trigger Update_Powerful on Contact (before update, before insert) {

//When contact Powerful connection checkbox is changed, update Account field

    // Loop through the incoming records
     for (Contact c : Trigger.new) {

        //Get account record
      Account a =c.Account;
           

        //Is Powerful connections ticked?
        
     a.Consultative_Selling_Partner__c = c.Powerful_Connections_Presentation_check__c;
            
            

   }


}

 

The error I receive on the contact when updating is:

Error:Apex trigger Update_Powerful caused an unexpected exception, contact your administrator: Update_Powerful: execution of BeforeUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contact.Email: Trigger.Update_Powerful: line 28, column 44

 

 

To give you an understanding of my overall goal with this, I want my users to tick a box on the event screen. Once that event is saved, if the box is ticked it updates the contact, which in turn updates the account. I've started with contact, since that seems to be an easier entry point to trigger design.

 

I guess my understanding falls down when I try to reference the account that's related to the contact, and edit that accounts fields. If anyone could point me int he right direction, I'd really appreciate it :)

 

 

 

Hi all,

 

With the help of users from this board I was able to write and implement triggers in my sandbox environment, the code for which is below. However, when I tried to move it to live it fell over, telling me I needed 75% code covereage. 

 

Could someone give me some insight into writing this test class? As far as I know it's about testing your interactions with records, but I'm not sure how to go about doing that.

 

 

}

trigger Contact_Update_SCIWorkflow on Event (before update, before insert)
{   
List<Contact> conForUpdate = new List<Contact>();       
for(Event e : Trigger.New)
    {

        if(e.whoid != null)
        {
            if(e.Consultative_Selling_Sci_Work_Flows__c == TRUE)
            {
                If(Trigger.IsInsert || (Trigger.IsUpdate && (Trigger.oldMap.get(e.Id).Consultative_Selling_Sci_Work_Flows__c !=Trigger.newMap.get(e.Id).Consultative_Selling_Sci_Work_Flows__c)
                                        )
                   )
                                {           
                                conForUpdate.add
                                    (
                                    new Contact
                                        (
                                        Id = e.WhoId,


                                        Consultative_Selling_Sci__c = TRUE,
                                        Consultative_Selling_SCI_Last_Pres_Date__c = e.Startdatetime


                                        )
                                    );       
                                }   
}       
 
 
 
 
if(conForUpdate != NULL && conForUpdate.size() > 0)
{update conForUpdate;}    

        }
    }

Hi everyone,

 

I'm new to Apex coding, so please forgive me if this question is amazingly basic.

 

I'm trying to build a trigger that fires when a contact record is edited. It should look at the value of a checkbox on the contact and use that to update the value of a checkbox on the contacts Account. 

 

This is what I have currently:

 

trigger Update_Powerful on Contact (before update, before insert) {

//When contact Powerful connection checkbox is changed, update Account field

    // Loop through the incoming records
     for (Contact c : Trigger.new) {

        //Get account record
      Account a =c.Account;
           

        //Is Powerful connections ticked?
        
     a.Consultative_Selling_Partner__c = c.Powerful_Connections_Presentation_check__c;
            
            

   }


}

 

The error I receive on the contact when updating is:

Error:Apex trigger Update_Powerful caused an unexpected exception, contact your administrator: Update_Powerful: execution of BeforeUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contact.Email: Trigger.Update_Powerful: line 28, column 44

 

 

To give you an understanding of my overall goal with this, I want my users to tick a box on the event screen. Once that event is saved, if the box is ticked it updates the contact, which in turn updates the account. I've started with contact, since that seems to be an easier entry point to trigger design.

 

I guess my understanding falls down when I try to reference the account that's related to the contact, and edit that accounts fields. If anyone could point me int he right direction, I'd really appreciate it :)