• Anna Suganthi
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
Create a new trigger to automatize the fulfillment of this field with other existing activity(ID) if the following conditions are true:
A new activity(event) is created with:
Type = meeting
Created by a user with Profile Name starting with "Sales Representative".
Subject contains "Initial Meeting" and does not contain "Additional" nor "Cancelled" nor "Resch".
The existing Activity (event) meets the following :
Subject does not contain "Additional" nor "Cancelled" nor "Resch".
Subject contains "Initial Meeting".
The contact/lead (WhoId) has the same Name in both activities (events).
The Start Date of both activities (events) is the same or separated 3 days at most.
If more than one match is found, select the oldest activity(event).

I tried the following, but am stuck in getting the user name with profile "Sales Representative"
trigger eventSetSameAs on Event (before insert) {
    Map<ID, Event> sameEvent = new Map<ID, Event>();
    //Check for the new event
    for(Event newEvent: system.trigger.new){
        Event oldEvent = System.Trigger.oldMap.get(newEvent.Id);
        //Get the list of users with profile Sales Representative
        List<User> userProfiles = [SELECT Id, Profile.Name FROM User WHERE Id IN : trigger.newMap.keySet() and Profile.Name = 'Sales Representative'];
        //Check for the following conditions
        if(newEvent.Type == 'Meeting' && 
           ((trigger.newMap.get(newEvent.id).subject.contains('Initial Meeting')) && 
             (!trigger.newMap.get(newEvent.id).subject.contains('Additional')) || 
              (!trigger.newMap.get(newEvent.id).subject.contains('Canceled')) || 
               (!trigger.newMap.get(newEvent.id).subject.contains('Resch')))) {
           if(newEvent.CreatedBy == )
            newEvent.Same_As__c = oldEvent.Id;
            }
        }
    }
Can you please help me in completing this trigger?
TIA
I have a RestClient test class. In the following part I get this error,
static testmethod void testGet() { 
        RestClientSpy spy = new RestClientSpy();
        
        spy.send(RequestMethods.GET.name(), '/services/data', null);
        
        System.assertEquals(1, spy.getSendCount());
        System.assertEquals(null, spy.getHttpRequest().getBody()); 
        System.assertEquals('GET', spy.getHttpRequest().getMethod()); 
    }

"System.AssertException: Assertion Failed: Expected: null, Actual:"
I tried different things to make it work, still am unable to figure it out. Can anyone help me in this please?
TIA.
Hello everyone, i have the following trigger test class. When i run the test I get the System.NullPointerException: Attempt to de-reference a null object error in line 59,
@isTest
private class accountNameDupePreventer {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Test.startTest();
        // First make sure there are no accounts already in the system
        // that have the Accounts used for testing
        Set<String> testAccountNames = new Set<String>();
        testAccountNames.add('Test1Dup Inc.');
        testAccountNames.add('Test2Dup Inc.');
        testAccountNames.add('Test3Dup Inc.');
        System.assert([SELECT count() FROM Account WHERE Name IN :testAccountNames] == 0);
    
        // Seed the database with some accounts, and make sure they can be bulk inserted successfully.
        Account account1 = new Account(Name = 'Test1Dup Inc.', BillingCountry = 'United States', BillingState = 'Texas');
        Account account2 = new Account(Name = 'Test4Dup Inc.', BillingCountry = 'United States', BillingState = 'California');
        Account account3 = new Account(Name = 'Test5Dup Inc.', BillingCountry = 'United States', BillingState = 'Florida');
        Account[] accts = new Account[] { account1, account2, account3 };
        insert accts;
        
        // Now make sure that some of these accounts can be changed and
        // then bulk updated successfully. Note that account1 is not
        // being changed, but is still being passed to the update
        // call. This should be OK.
        account2.Name = 'Test2Dup Inc.';
        account3.Name = 'Test3Dup Inc.';
        update accts;
        
        // Make sure that single row account duplication prevention works on insert.
        Account dup1 = new Account(Name='Test1Dup Inc.', BillingCountry = 'United States');
        try {
            insert dup1;
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 1);
            System.assert(e.getDmlIndex(0) == 0);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that single row account duplication prevention works on update.
        dup1 = new Account(Id=account1.Id, Name='Test3Dup Inc.', BillingCountry = 'United States');
        try {
            update dup1;
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 1);
            System.assert(e.getDmlIndex(0) == 0);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that bulk account duplication prevention works on
        // insert. Note that the first item being inserted is fine,
        // but the second and third items are duplicates. Note also
        // that since at least one record insert fails, the entire
        // transaction will be rolled back.
        dup1 = new Account(Name='Test4Dup Inc.', BillingCountry = 'United States');
        Account dup2 = new Account(Name='Test2Dup Inc.', BillingCountry = 'United States');
        Account dup3 = new Account(Name='Test3Dup Inc.', BillingCountry = 'United States');
        Account[] dups = new Account[] {dup1, dup2, dup3};
        try {
            insert dups;
            System.assert(false);
        } catch (DmlException e) {
            // Num=2 because dup1 not fails
            System.assert(e.getNumDml() == 2);
            // dup2 fails
            System.assert(e.getDmlIndex(0) == 1);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
            // dup3 fails
            System.assert(e.getDmlIndex(1) == 2);
            System.assert(e.getDmlFields(1).size() == 1);
            System.assert(e.getDmlFields(1)[0] == Account.Name);
            System.assert(e.getDmlMessage(1).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that bulk account duplication prevention works on
        // update. Note that the first item being updated is fine,
        // because the name is new, and the second item is
        // also fine, but in this case it's because the 
        // name doesn't change. The third case is flagged as an
        // error because it is a duplicate of the name of the
        // first account's value in the database, even though that value
        // is changing in this same update call. It would be an
        // interesting exercise to rewrite the trigger to allow this
        // case. Note also that since at least one record update
        // fails, the entire transaction will be rolled back.
        dup1 = new Account(Id=account1.id, Name='Test5Dup Inc.', BillingCountry = 'United States');
        dup2 = new Account(Id=account2.id, Name='Test2Dup Inc.', BillingCountry = 'United States');
        dup3 = new Account(Id=account3.id, Name='Test1Dup Inc.', BillingCountry = 'United States');
        dups = new Account[] {dup1, dup2, dup3};
        try {
            update dups;
            System.assert(false);
        } catch (DmlException e) {
            System.debug(e.getNumDml());
            System.debug(e.getDmlMessage(0));
            System.assert(e.getNumDml() == 1);
            System.assert(e.getDmlIndex(0) == 2);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that duplicates in the submission are caught when
        // inserting accounts. Note that this test also catches an
        // attempt to insert an account where there is an existing
        // duplicate.
        dup1 = new Account(Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup2 = new Account(Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup3 = new Account(Name='Test3Dup Inc.', BillingCountry = 'United States');
        dups = new Account[] {dup1, dup2, dup3};
        try {
                insert dups;
                System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 2);
            System.assert(e.getDmlIndex(0) == 1);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'Another inserted/updated account from bulk operation has the same name.') > -1);
            System.assert(e.getDmlIndex(1) == 2);
            System.assert(e.getDmlFields(1).size() == 1);
            System.assert(e.getDmlFields(1)[0] == Account.Name);
            System.assert(e.getDmlMessage(1).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that duplicates in the submission are caught when
        // updating accounts. Note that this test also catches an attempt
        // to update an account where there is an existing duplicate.
        dup1 = new Account(Id=account1.id, Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup2 = new Account(Id=account2.id, Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup3 = new Account(Id=account3.id, Name='Test2Dup Inc.', BillingCountry = 'United States');
        dups = new Account[] {dup1, dup2, dup3};
        try {
            update dups;
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 2);
            System.assert(e.getDmlIndex(0) == 1);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'Another inserted/updated account from bulk operation has the same name.') > -1);
            System.assert(e.getDmlIndex(1) == 2);
            System.assert(e.getDmlFields(1).size() == 1);
            System.assert(e.getDmlFields(1)[0] == Account.Name);
            System.assert(e.getDmlMessage(1).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        Test.stopTest();
    }
}

"System.assert(e.getDmlFields(0).size() == 1);", the error is thrown in this line. Can anyone tell me how to solve this?
ThanksinAdvance!
Hi all,

Am a beginner to Salesforce development and Apex . I have a scenario where i need to create a trigger to update the account status to "Ëngaged" whenever the contact with Event subject "Initial Meeting" changes to "Sales Qualified". I have written the trigger for it. But now, stuck with the test class. Here is my trigger, 
trigger contactSetEngagedAccount on contact (after update){
    
    Map<ID, Contact> contactsToCheck = new Map<ID, Contact>();
    
    for (Contact updatedContact : System.Trigger.new){
       
        Contact oldContact = System.Trigger.oldMap.get(updatedContact.Id);
        
        //If the contact status is updated to "Sales Qualified" then update the Map      
        if(oldContact.contact_status__c != updatedContact.contact_status__c && updatedContact.Contact_Status__c.compareTo('Sales Qualified') == 0){
            
            contactsToCheck.put(updatedContact.Id,updatedContact);
        }
            // Check for events with Initial Meeting
            // 
            
        
        List<Event> eventList=([select WhoId, subject From Event where WhoId IN :contactsToCheck.keySet() and (subject = 'Initial Meeting')]);
        
        Set<ID> contactIds = new Set<ID>();
        for(Event eventId:eventList) {
            
            contactIds.add(eventId.WhoId);
        }
        
       // get the list of accounts          
       List<Account> accountList = 
            [select id, Status__c from Account 
             where Status__c IN ('Prospect', '') 
             and Id in (select AccountId from Contact where Id IN :contactIds)];
        
        // change the account status to Engaged
        for (Account oneAccount : accountList ) {
            oneAccount.Status__c = 'Engaged';               
        }
        
        // Update accounts
        update accountList;
        
    }
}

Can anyone please help me with the test class. It will be very helpful!!! TIA.
I have a RestClient test class. In the following part I get this error,
static testmethod void testGet() { 
        RestClientSpy spy = new RestClientSpy();
        
        spy.send(RequestMethods.GET.name(), '/services/data', null);
        
        System.assertEquals(1, spy.getSendCount());
        System.assertEquals(null, spy.getHttpRequest().getBody()); 
        System.assertEquals('GET', spy.getHttpRequest().getMethod()); 
    }

"System.AssertException: Assertion Failed: Expected: null, Actual:"
I tried different things to make it work, still am unable to figure it out. Can anyone help me in this please?
TIA.
Create a new trigger to automatize the fulfillment of this field with other existing activity(ID) if the following conditions are true:
A new activity(event) is created with:
Type = meeting
Created by a user with Profile Name starting with "Sales Representative".
Subject contains "Initial Meeting" and does not contain "Additional" nor "Cancelled" nor "Resch".
The existing Activity (event) meets the following :
Subject does not contain "Additional" nor "Cancelled" nor "Resch".
Subject contains "Initial Meeting".
The contact/lead (WhoId) has the same Name in both activities (events).
The Start Date of both activities (events) is the same or separated 3 days at most.
If more than one match is found, select the oldest activity(event).

I tried the following, but am stuck in getting the user name with profile "Sales Representative"
trigger eventSetSameAs on Event (before insert) {
    Map<ID, Event> sameEvent = new Map<ID, Event>();
    //Check for the new event
    for(Event newEvent: system.trigger.new){
        Event oldEvent = System.Trigger.oldMap.get(newEvent.Id);
        //Get the list of users with profile Sales Representative
        List<User> userProfiles = [SELECT Id, Profile.Name FROM User WHERE Id IN : trigger.newMap.keySet() and Profile.Name = 'Sales Representative'];
        //Check for the following conditions
        if(newEvent.Type == 'Meeting' && 
           ((trigger.newMap.get(newEvent.id).subject.contains('Initial Meeting')) && 
             (!trigger.newMap.get(newEvent.id).subject.contains('Additional')) || 
              (!trigger.newMap.get(newEvent.id).subject.contains('Canceled')) || 
               (!trigger.newMap.get(newEvent.id).subject.contains('Resch')))) {
           if(newEvent.CreatedBy == )
            newEvent.Same_As__c = oldEvent.Id;
            }
        }
    }
Can you please help me in completing this trigger?
TIA
Hello everyone, i have the following trigger test class. When i run the test I get the System.NullPointerException: Attempt to de-reference a null object error in line 59,
@isTest
private class accountNameDupePreventer {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Test.startTest();
        // First make sure there are no accounts already in the system
        // that have the Accounts used for testing
        Set<String> testAccountNames = new Set<String>();
        testAccountNames.add('Test1Dup Inc.');
        testAccountNames.add('Test2Dup Inc.');
        testAccountNames.add('Test3Dup Inc.');
        System.assert([SELECT count() FROM Account WHERE Name IN :testAccountNames] == 0);
    
        // Seed the database with some accounts, and make sure they can be bulk inserted successfully.
        Account account1 = new Account(Name = 'Test1Dup Inc.', BillingCountry = 'United States', BillingState = 'Texas');
        Account account2 = new Account(Name = 'Test4Dup Inc.', BillingCountry = 'United States', BillingState = 'California');
        Account account3 = new Account(Name = 'Test5Dup Inc.', BillingCountry = 'United States', BillingState = 'Florida');
        Account[] accts = new Account[] { account1, account2, account3 };
        insert accts;
        
        // Now make sure that some of these accounts can be changed and
        // then bulk updated successfully. Note that account1 is not
        // being changed, but is still being passed to the update
        // call. This should be OK.
        account2.Name = 'Test2Dup Inc.';
        account3.Name = 'Test3Dup Inc.';
        update accts;
        
        // Make sure that single row account duplication prevention works on insert.
        Account dup1 = new Account(Name='Test1Dup Inc.', BillingCountry = 'United States');
        try {
            insert dup1;
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 1);
            System.assert(e.getDmlIndex(0) == 0);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that single row account duplication prevention works on update.
        dup1 = new Account(Id=account1.Id, Name='Test3Dup Inc.', BillingCountry = 'United States');
        try {
            update dup1;
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 1);
            System.assert(e.getDmlIndex(0) == 0);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that bulk account duplication prevention works on
        // insert. Note that the first item being inserted is fine,
        // but the second and third items are duplicates. Note also
        // that since at least one record insert fails, the entire
        // transaction will be rolled back.
        dup1 = new Account(Name='Test4Dup Inc.', BillingCountry = 'United States');
        Account dup2 = new Account(Name='Test2Dup Inc.', BillingCountry = 'United States');
        Account dup3 = new Account(Name='Test3Dup Inc.', BillingCountry = 'United States');
        Account[] dups = new Account[] {dup1, dup2, dup3};
        try {
            insert dups;
            System.assert(false);
        } catch (DmlException e) {
            // Num=2 because dup1 not fails
            System.assert(e.getNumDml() == 2);
            // dup2 fails
            System.assert(e.getDmlIndex(0) == 1);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
            // dup3 fails
            System.assert(e.getDmlIndex(1) == 2);
            System.assert(e.getDmlFields(1).size() == 1);
            System.assert(e.getDmlFields(1)[0] == Account.Name);
            System.assert(e.getDmlMessage(1).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that bulk account duplication prevention works on
        // update. Note that the first item being updated is fine,
        // because the name is new, and the second item is
        // also fine, but in this case it's because the 
        // name doesn't change. The third case is flagged as an
        // error because it is a duplicate of the name of the
        // first account's value in the database, even though that value
        // is changing in this same update call. It would be an
        // interesting exercise to rewrite the trigger to allow this
        // case. Note also that since at least one record update
        // fails, the entire transaction will be rolled back.
        dup1 = new Account(Id=account1.id, Name='Test5Dup Inc.', BillingCountry = 'United States');
        dup2 = new Account(Id=account2.id, Name='Test2Dup Inc.', BillingCountry = 'United States');
        dup3 = new Account(Id=account3.id, Name='Test1Dup Inc.', BillingCountry = 'United States');
        dups = new Account[] {dup1, dup2, dup3};
        try {
            update dups;
            System.assert(false);
        } catch (DmlException e) {
            System.debug(e.getNumDml());
            System.debug(e.getDmlMessage(0));
            System.assert(e.getNumDml() == 1);
            System.assert(e.getDmlIndex(0) == 2);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that duplicates in the submission are caught when
        // inserting accounts. Note that this test also catches an
        // attempt to insert an account where there is an existing
        // duplicate.
        dup1 = new Account(Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup2 = new Account(Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup3 = new Account(Name='Test3Dup Inc.', BillingCountry = 'United States');
        dups = new Account[] {dup1, dup2, dup3};
        try {
                insert dups;
                System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 2);
            System.assert(e.getDmlIndex(0) == 1);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'Another inserted/updated account from bulk operation has the same name.') > -1);
            System.assert(e.getDmlIndex(1) == 2);
            System.assert(e.getDmlFields(1).size() == 1);
            System.assert(e.getDmlFields(1)[0] == Account.Name);
            System.assert(e.getDmlMessage(1).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        
        // Make sure that duplicates in the submission are caught when
        // updating accounts. Note that this test also catches an attempt
        // to update an account where there is an existing duplicate.
        dup1 = new Account(Id=account1.id, Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup2 = new Account(Id=account2.id, Name='Test4Dup Inc.', BillingCountry = 'United States');
        dup3 = new Account(Id=account3.id, Name='Test2Dup Inc.', BillingCountry = 'United States');
        dups = new Account[] {dup1, dup2, dup3};
        try {
            update dups;
            System.assert(false);
        } catch (DmlException e) {
            System.assert(e.getNumDml() == 2);
            System.assert(e.getDmlIndex(0) == 1);
            System.assert(e.getDmlFields(0).size() == 1);
            System.assert(e.getDmlFields(0)[0] == Account.Name);
            System.assert(e.getDmlMessage(0).indexOf(
            'Another inserted/updated account from bulk operation has the same name.') > -1);
            System.assert(e.getDmlIndex(1) == 2);
            System.assert(e.getDmlFields(1).size() == 1);
            System.assert(e.getDmlFields(1)[0] == Account.Name);
            System.assert(e.getDmlMessage(1).indexOf(
            'An account with this account\'s name already exists.') > -1);
        }
        Test.stopTest();
    }
}

"System.assert(e.getDmlFields(0).size() == 1);", the error is thrown in this line. Can anyone tell me how to solve this?
ThanksinAdvance!
Hi all,

Am a beginner to Salesforce development and Apex . I have a scenario where i need to create a trigger to update the account status to "Ëngaged" whenever the contact with Event subject "Initial Meeting" changes to "Sales Qualified". I have written the trigger for it. But now, stuck with the test class. Here is my trigger, 
trigger contactSetEngagedAccount on contact (after update){
    
    Map<ID, Contact> contactsToCheck = new Map<ID, Contact>();
    
    for (Contact updatedContact : System.Trigger.new){
       
        Contact oldContact = System.Trigger.oldMap.get(updatedContact.Id);
        
        //If the contact status is updated to "Sales Qualified" then update the Map      
        if(oldContact.contact_status__c != updatedContact.contact_status__c && updatedContact.Contact_Status__c.compareTo('Sales Qualified') == 0){
            
            contactsToCheck.put(updatedContact.Id,updatedContact);
        }
            // Check for events with Initial Meeting
            // 
            
        
        List<Event> eventList=([select WhoId, subject From Event where WhoId IN :contactsToCheck.keySet() and (subject = 'Initial Meeting')]);
        
        Set<ID> contactIds = new Set<ID>();
        for(Event eventId:eventList) {
            
            contactIds.add(eventId.WhoId);
        }
        
       // get the list of accounts          
       List<Account> accountList = 
            [select id, Status__c from Account 
             where Status__c IN ('Prospect', '') 
             and Id in (select AccountId from Contact where Id IN :contactIds)];
        
        // change the account status to Engaged
        for (Account oneAccount : accountList ) {
            oneAccount.Status__c = 'Engaged';               
        }
        
        // Update accounts
        update accountList;
        
    }
}

Can anyone please help me with the test class. It will be very helpful!!! TIA.
hi all,

I urgently need to edit/delete a post made by me on this discussion forum...But its not allowing me to do so and pops up
saying that 'you cant delete this question as others are interested in it'.
There are no likes and no comments on it still i am unable  to delete it
Any help would be highly appreciated

Its very urgent,
Thanks,