• Cindy GUILLET
  • NEWBIE
  • 25 Points
  • Member since 2018

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

I have a flow which add informations from children records of cases.
In the text field I obtain : 1.5.663,1.5.458,1.5.663,1.4.985
I need to remove duplicates in order to display : 1.5.663,1.5.458,1.4.985

I wrote a trigger based on what I found on many forums but I'm new on Apex and I can't figure it out.

trigger Trg_Case on Case (after update) {
    For(Case myCase: Trigger.new){
        if(myCase.ChildrenVersions__c != null && (myCase.ChildrenVersions__c).contains(',')){
            string reports = myCase.ChildrenVersions__c;
            List<String> l = new List<String>(new Set<String>(reports.split(',')));
            String uniqueReports = String.join(l, ',');
        }
    }
}

Thanks for your answers
Hello,
I'm a beginner with triggers and test classes.
I can't manage to cover the trigger below.

Thanks for your help.

Trigger EventBeforeUpdate on Event (before insert, before update){
   
    If(AvoidRecursion.isFirstRun()){
        If(!AdminSettings__c.getInstance().DisableTg__c){
            For (Event myEvent: trigger.new){
                If(Trigger.isInsert) {
                }
       
                If(Trigger.isUpdate){
                    If(UserInfo.getUserId()!= myEvent.OwnerId && UserInfo.getUserId()!= '00524000001WRNAAA4'&& myEvent.RecordTypeId == '0121o00000113r3' && trigger.oldMap.get(myEvent.Id).OwnerId == myEvent.OwnerId)
                    {
                    myEvent.adderror('ERROR1');
                    }
                    If(UserInfo.getUserId()!= myEvent.OwnerId && myEvent.RecordTypeId != '0121o00000113r3' && trigger.oldMap.get(myEvent.Id).OwnerId == myEvent.OwnerId)
                    {
                    myEvent.adderror('ERROR2.');
                    }
                }
            }
        }
    }
}


My Test :

@isTest
public class EventBeforeUpdateTest{
   
    private static User makeStandardUser(String p_firstName, String p_lastName) {
       
        User standardUser = new User();
       
        standardUser.LastName = p_lastName;
        standardUser.FirstName = p_firstName;
        standardUser.Alias = 'JPJ';
        standardUser.CommunityNickname = p_firstName + ' ' + p_lastName;
        standardUser.UserName = p_firstName + p_lastName + '@softwaymedical.fr';
        standardUser.Email = 'dev@dev.com';
        standardUser.TimeZoneSidKey = 'America/Los_Angeles';
        standardUser.LocaleSidKey = 'en_US';
        standardUser.EmailEncodingKey = 'UTF-8';
        standardUser.LanguageLocaleKey = 'en_US';
        standardUser.profileId = '00e24000000tqX0';
       
        return standardUser;
    }
   
    static testMethod void createAndUpdateEventTest() {
       
        User User1 = makeStandardUser('JUL', 'JAV');
        User User2 = makeStandardUser('CGL', 'GUI');
       
        Insert User1;
        Insert User2;
       
        AdminSettings__c setting = new AdminSettings__c(SetupOwnerId=Userinfo.getUserId());
        setting.DisablePb__c = True;
       
        Insert setting;
       
        Event myEvent1 = new Event();
        myEvent1.RecordTypeId = '0121o00000113r4';
        myEvent1.Subject = 'New Event Standard';
        myEvent1.StartDateTime = system.Now();
        myEvent1.EndDateTime = system.Now();
        myEvent1.OwnerId = User1.Id;
       
        Insert myEvent1;
          system.runAs(User2){
            try{
                Update myEvent1;
                }catch(Exception ex){
          }
        }
       
        system.runAs(User1){
            try{
                Update myEvent1;
            }catch(Exception ex){     
            }
        }
    }
}
 
Hello, I managed to send a notification email to all event Invitees using Visual Workflow.
I'm now searching a way to include the link to the event in this email. But, the ID is different :
Example :
id of the event for the owner : 00U6E0000021pVY
id of the event for the first invitee : 00U6E0000021pVZ
id of the event for the second invitee : 00U6E0000021pVa
And I only managed to get the first one.
Does anyone has an idea ?
Hello,

I have a flow which add informations from children records of cases.
In the text field I obtain : 1.5.663,1.5.458,1.5.663,1.4.985
I need to remove duplicates in order to display : 1.5.663,1.5.458,1.4.985

I wrote a trigger based on what I found on many forums but I'm new on Apex and I can't figure it out.

trigger Trg_Case on Case (after update) {
    For(Case myCase: Trigger.new){
        if(myCase.ChildrenVersions__c != null && (myCase.ChildrenVersions__c).contains(',')){
            string reports = myCase.ChildrenVersions__c;
            List<String> l = new List<String>(new Set<String>(reports.split(',')));
            String uniqueReports = String.join(l, ',');
        }
    }
}

Thanks for your answers
Hello,
I'm a beginner with triggers and test classes.
I can't manage to cover the trigger below.

Thanks for your help.

Trigger EventBeforeUpdate on Event (before insert, before update){
   
    If(AvoidRecursion.isFirstRun()){
        If(!AdminSettings__c.getInstance().DisableTg__c){
            For (Event myEvent: trigger.new){
                If(Trigger.isInsert) {
                }
       
                If(Trigger.isUpdate){
                    If(UserInfo.getUserId()!= myEvent.OwnerId && UserInfo.getUserId()!= '00524000001WRNAAA4'&& myEvent.RecordTypeId == '0121o00000113r3' && trigger.oldMap.get(myEvent.Id).OwnerId == myEvent.OwnerId)
                    {
                    myEvent.adderror('ERROR1');
                    }
                    If(UserInfo.getUserId()!= myEvent.OwnerId && myEvent.RecordTypeId != '0121o00000113r3' && trigger.oldMap.get(myEvent.Id).OwnerId == myEvent.OwnerId)
                    {
                    myEvent.adderror('ERROR2.');
                    }
                }
            }
        }
    }
}


My Test :

@isTest
public class EventBeforeUpdateTest{
   
    private static User makeStandardUser(String p_firstName, String p_lastName) {
       
        User standardUser = new User();
       
        standardUser.LastName = p_lastName;
        standardUser.FirstName = p_firstName;
        standardUser.Alias = 'JPJ';
        standardUser.CommunityNickname = p_firstName + ' ' + p_lastName;
        standardUser.UserName = p_firstName + p_lastName + '@softwaymedical.fr';
        standardUser.Email = 'dev@dev.com';
        standardUser.TimeZoneSidKey = 'America/Los_Angeles';
        standardUser.LocaleSidKey = 'en_US';
        standardUser.EmailEncodingKey = 'UTF-8';
        standardUser.LanguageLocaleKey = 'en_US';
        standardUser.profileId = '00e24000000tqX0';
       
        return standardUser;
    }
   
    static testMethod void createAndUpdateEventTest() {
       
        User User1 = makeStandardUser('JUL', 'JAV');
        User User2 = makeStandardUser('CGL', 'GUI');
       
        Insert User1;
        Insert User2;
       
        AdminSettings__c setting = new AdminSettings__c(SetupOwnerId=Userinfo.getUserId());
        setting.DisablePb__c = True;
       
        Insert setting;
       
        Event myEvent1 = new Event();
        myEvent1.RecordTypeId = '0121o00000113r4';
        myEvent1.Subject = 'New Event Standard';
        myEvent1.StartDateTime = system.Now();
        myEvent1.EndDateTime = system.Now();
        myEvent1.OwnerId = User1.Id;
       
        Insert myEvent1;
          system.runAs(User2){
            try{
                Update myEvent1;
                }catch(Exception ex){
          }
        }
       
        system.runAs(User1){
            try{
                Update myEvent1;
            }catch(Exception ex){     
            }
        }
    }
}