function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mdex Centre-VilleMdex Centre-Ville 

Organization Code coverage and code coverage for a very simple trigger

Hi

I made a very simple trigger to update some fields in my event.
 
1 trigger Updatelookup on Event (before insert, before update){
2    for (event u : Trigger.new){
3        u.lookup_contact__c = u.WhoId;
4        u.Subject = u.Nom_formate__c + u.Raison_visite_formate__c;
5        }
6 }
In the sandbox, it's working very well event if it decrare that the coverage is "0"
When I try to deploy it I receeve this error :

""""Code Coverage Failure Your organization's code coverage is 59%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
: Updatelookup""""

The thins is that I have no idea about what refer these coverage and then about how I can fix this error.
I also have no knowledge in coding so ...

Thx a lot for your help
Pankaj_GanwaniPankaj_Ganwani
Hi,

First you can create test class something like this:
 
@isTest
private class TestForEvent
{
   Contact objContact = new Contact(LastName = 'Test Contact'); 
   insert objContact;

   Event objEvent = new Event(Subject = 'Test', StartDateTime = Date.Today(), EndDateTime = Date.Today().addDays(5), WhoId = objContact.Id);
  insert objEvent;
}

By looking at your code, it seems lookup_contact__c field is lookup to Contact. In this case, you must check whether the WhoId belongs to Contact or Lead. If this is Contact, then only it should be assigned to lookup_contact__c.

 
Mdex Centre-VilleMdex Centre-Ville
Hi.
Thx for your answer.

Are you sure about your code ?  If I copy it it Says that it miss "{" at the line 5 before "insert objContact;"

if I add  { and } at the end, it said the code is correct but when I test it says "succed" but  0/0 so .... nothing to succed

Yes, the lookup contact is a custom lookup in event that point on contact.  I populate it from the WhoId. (In event, only contact are entered, we never use lead in event)
Mdex Centre-VilleMdex Centre-Ville
Hi again.
 I wrote your code like that. I had to add methode because it was not working.  Now, I have a success 1/1 

When I try to deploy it, I receve this message "

Code Coverage Failure Your organization's code coverage is 61%. You need at least 75% coverage to complete this deployment.

in details


Error Message
Details: Average test coverage across all Apex Classes and Triggers is 61%, at least 75% test coverage is required.

WarehouseDataInstall.testWarehouseDataInstall(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, There's a problem with this state, even though it may appear correct. Please select a state from the list of valid states.: [BillingState] Class.WarehouseDataInstall.createData: line 16, column 1 Class.WarehouseDataInstall.testWarehouseDataInstall: line 91, column 1

The second point ... I guess it's the NPSP but ..... I have no ideas about the connection with WarehouseDataInstall and my own trigger ?

If not, How Can I up from 61% to 100% ?
@isTest 
private class Updatelookup {
static testMethod void insertNewEvent() {
 
Contact objContact = new Contact(LastName = 'Test Contact');  
insert objContact; 

Event objEvent = new Event(Subject = 'Test', StartDateTime = Date.Today(), EndDateTime = Date.Today().addDays(5), WhoId = objContact.Id); 
insert objEvent; 
} }

 
Pankaj_GanwaniPankaj_Ganwani
Hi,

When you validate the change set in other org, then all the test classes are run which are present in that org. Here, your Event test class is working properly, but WarehouseDataInstall is having test failures, so you will have to firstly resolve the failures in sandbox and then deploy that artifact as well along with your present artifacts(Event trigger, handler and test class).

Note : The overall coverage of the org should be 75% to deploy the code to other org(Production in your case). If any of the test classes(present in that org) is having failures, then change set validation will be failed and artifacts cannot be deployed.
 
Mdex Centre-VilleMdex Centre-Ville
Hi.

Yes, I corrected WarehouseDataInstall and it's working.

But now I discovered another problem lol.... I'm discourage

What I wanted to do, is:
1) When I create an event in google cal, data are transfered to Salesforce (I use groove so I can add custom field)
2) Salesforce, from Who Id is supposed to feed "lookup_contact__c"
3) Nom_formate__c is a formula Field that extract first and Last name from "lookup_contact__c"
3) From Nom_formate__c and Raison_visite_formate__c, Salesforce update Event title.
4) Event Title is sync in google calendar

When I enter the event directly in Salesforce, everything is working well. (Because no link with google)

But, when I'm creating the event on google calendar, nothing work. "lookup_contact__c" is not populated exept is I update the event (In google or salesforce)
Then, on my new event title, I only have "Raison_visite_formate__c" and not the name.

I can guess that it's because the trigger start before the WhoId is set-up so, the command to feed lookup_contact__c find nothing.

I don't really know how to resolve that.

Maybe if I could directly take The name from the WhoId without using lookup_contact__c it will help but it stay that it seems that the trigger works before WhoId is populated by google so .... I'm totally blocked :(