• David Hagen
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Hi Guys,

I have a system call 'X' which runs cronjob to inserts/update records in SF ojects(contact,task).  I also have triggers(insert,update) with callout to system 'X' on the objects. I reach the maximum number of AP calls 28,000. I know there is no way System X can send 28,000 Api calls. Not sure whats happening. I thought it's loop so, I have added on triggers, if the changes are made by the same user as system X don't fire the trigger.
 
Hi, I'm totally new to salesforce.  I have a trigger which calls external URL on insert and update.
I can't get 100% code coverage. I get 81% at sandbox but on production i get less then 75%.
Here is my trigger
trigger EmsTrigger on Contact (after insert, after update){
    List<Contact> contactsToUpdate = new List<Contact>{};
    String id;
   for (Contact con: Trigger.new){
        contactsToUpdate.add(con);
        id=con.Id;
   }
   if(!contactsToUpdate.isEmpty()){
      if(UserInfo.getProfileId()!='hidden profileid'){
        Integer i=[select count() from Enrolment__c WHERE contact__c=:id];
          if(i>0){
            String JSONString = JSON.serialize(contactsToUpdate);
            Ems.doCallout(JSONString);
          }
      }
        
    }
}
My unit test
@IsTest

public class testEmsTrigger {
    
    static testmethod void insertContact(){
      Contact con = new Contact();
      con.FirstName='David';
      con.LastName='Hagen';
      insert con;
     
       Test.startTest();
       Test.setMock(HttpCalloutMock.class, new ExampleCalloutMock());
       Test.stopTest();
    }
}

I think issue is here in the following line which does not excute when test is run.
if(i>0){
}
 
Hi, I've a trigger on insert and update task. I uses both API and Web to insert/update task. I would like to stop triggers when they are updated by API. So, added a filter to check if the user is API then do nothing. I can't increase the code coverage in the following code

trigger XmsTaskTrigger on Task (after insert, after update) {
    Task[] tsk = Trigger.new;
       String JSONString = JSON.serialize(tsk);
      if(UserInfo.getProfileId()!='API'){
       XmsTask.doCallout(JSONString);
    }
 }

If I remove   if(UserInfo.getProfileId()!='API') I get 94% code coverage otherwise i get 50%
Hi, I'm totally new to salesforce.  I have a trigger which calls external URL on insert and update.
I can't get 100% code coverage. I get 81% at sandbox but on production i get less then 75%.
Here is my trigger
trigger EmsTrigger on Contact (after insert, after update){
    List<Contact> contactsToUpdate = new List<Contact>{};
    String id;
   for (Contact con: Trigger.new){
        contactsToUpdate.add(con);
        id=con.Id;
   }
   if(!contactsToUpdate.isEmpty()){
      if(UserInfo.getProfileId()!='hidden profileid'){
        Integer i=[select count() from Enrolment__c WHERE contact__c=:id];
          if(i>0){
            String JSONString = JSON.serialize(contactsToUpdate);
            Ems.doCallout(JSONString);
          }
      }
        
    }
}
My unit test
@IsTest

public class testEmsTrigger {
    
    static testmethod void insertContact(){
      Contact con = new Contact();
      con.FirstName='David';
      con.LastName='Hagen';
      insert con;
     
       Test.startTest();
       Test.setMock(HttpCalloutMock.class, new ExampleCalloutMock());
       Test.stopTest();
    }
}

I think issue is here in the following line which does not excute when test is run.
if(i>0){
}
 
Hi, I've a trigger on insert and update task. I uses both API and Web to insert/update task. I would like to stop triggers when they are updated by API. So, added a filter to check if the user is API then do nothing. I can't increase the code coverage in the following code

trigger XmsTaskTrigger on Task (after insert, after update) {
    Task[] tsk = Trigger.new;
       String JSONString = JSON.serialize(tsk);
      if(UserInfo.getProfileId()!='API'){
       XmsTask.doCallout(JSONString);
    }
 }

If I remove   if(UserInfo.getProfileId()!='API') I get 94% code coverage otherwise i get 50%