• Robert Wambold 10
  • NEWBIE
  • 60 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 13
    Replies

In SOQL...select id, whatid from task where WHAT.TYPE = 'Opportunity'.

Is there an alternative to WHAT.TYPE in APEX.

Hello All,

My code valdiated fine on 07/02/2019, but now fails Valdiation. No code was changed. Any idea?

Thank you.

Robert

 

Error:

System.AssertException: Assertion Failed 

Stack Trace: Class.WebToWebLeadControllerTest.getWebToWebLeadControllerTest: line 19, column 1

 

public class WebToWebLeadControllerTest 

19   System.assert(webToWebLeadCtrl.save() != null);

 

public class WebToWebLeadController 

public pagereference save(){
        try{
            update webCase;
            PageReference thankyouPage = new PageReference('/webtocasethankyou');
          return thankyouPage;
        }catch(Exception e){
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Unknown Error');
            ApexPages.addMessage(myMsg);
        }
        return null;
    }

 

 

Hi All,

On my Pre Chat form I want the text to wrap to other lines rather than one really really long line. How would you do this on an input field?

With thanks in advance.

Robert

 

The code below doesn't do what I want. :(

<input style="margin-left: 36px;height: 100px;word-wrap: break-word;" type='text' name='liveagent.prechat:CaseSubject' id='subject' /><br /> 

 

Hello all,

So I created a trigger to Cases in a queue, when size is reached I want to send an email once..only once.

My trigger is firing at limit (3), but is sending the email 3 times. I think I need a second or third set of eyes to see what I am missing.

Thanks for your help.

Robert 

trigger NotificationExceedingQueueLimit3 on Case (before insert,before update) {

boolean EmailSent = False;

    list<group> queuelist= [SELECT id  FROM Group where DeveloperName = 'CPS_Default_Queue'and Type = 'Queue' limit 1];     
    if(queuelist.size()>0){
                
             list<case> caselist = [select id from case where ownerid =:queuelist[0].id];
             for(case cs : trigger.new){
             
                if(caselist.size()==3 && EmailSent == False)
                {
                  EmailSent = True; 
                  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
                  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                  List<String> sendTo = new List<String>();
                  sendTo.add('Hello.Friend@gmail.com' );
                  mail.setHtmlBody('Hello, <br/> Default Queue Limit Exceeded. The count has exceeded 2 cases.<br/><br/> Thanks, <br/>Salesforce Admin');
                  mail.setSubject('Case Limit of 02 Exceeded');
                  mail.setToAddresses(sendTo);
                  mails.add(mail);   
                  Messaging.sendEmail(mails); 
                }
        
             }
    }  
}
 

 

 

Hello All,

I have a simple trigger, PreventCCDeletion that should only allow Users with Profile='System Administrator-2012' or with Permission Set='Super User'  to delete Case Comments. The trigger works well...unfortunately I cannot reach the proper Code Coverage and cannot get over 66%.

Thanks in advance for your help.

Kned regards,

Robert

User-added image

Here is my trigger:

trigger PreventCCDeletion on CaseComment (before delete) {

Boolean YouCanDelete;
YouCanDelete=FALSE; 

    for(CaseComment cc : trigger.old)
    {
       
    // Check for 'System Administrator-2012' Profile
    
      List<Profile> PROFILE = [SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId() LIMIT 1];
      String MyProfileName = PROFILE[0].Name;
      If (MyProfileName=='System Administrator-2012'){ 
        YouCanDelete=TRUE;
      }
    
   
     // Check for 'Super User' ( 0PS0y000000D0dvGAC ) Permission Set
     
     If (YouCanDelete=FALSE){
        List<PermissionSetAssignment> SUPERUSER = [SELECT PermissionSet.Name FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'Super_User' LIMIT 1];
        String MyPermissionName = SUPERUSER[0].PermissionSet.Name;
          If (MyPermissionName=='Super_User'){   
          YouCanDelete=TRUE;
        }
      }
  
      If (YouCanDelete=FALSE) 
      { 
        cc.adderror('Case Comments cannot be deleted');
      }
    } 
}
 

Here is my test class:

@isTest
public class PreventCCDeletion_Test{
    
    static Case tCase;
    static CaseComment tComment;
    static Profile tProfile;
    static User tUser;
    
// Start of Test 1    
    static void createTestData1(){
        tCase = new Case();
        tCase.Status = 'Open';
        tCase.Description = 'Test Description-1 ';
        tCase.Origin = 'Annuity External';
        tCase.Type = 'Feature Request';
        tCase.Priority = 'Low';
        INSERT tCase;
        
        tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Some Comment-1';
        tComment.IsPublished = TRUE;
        INSERT tComment;
        
        tProfile = 
            [
                SELECT Id 
                FROM   Profile 
                WHERE  Name = 'System Administrator-2012'
            ];
            
        tUser = new User(
            Alias = 'standt', 
            Email='standarduser@testorg.com', 
            EmailEncodingKey='UTF-8', 
            LastName='Testing', 
            LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', 
            ProfileId = tProfile.Id, 
            TimeZoneSidKey='America/Los_Angeles', 
            UserName='testuser@sometestorg.com',
            Non_Use_Send_Deactivation_Alert__c=FALSE,
            DefaultCurrencyIsoCode='USD',
            CurrencyIsoCode='USD',
            ReceivesAdminInfoEmails=FALSE,
            ByPass_New_Hire_Welcome__c=TRUE
        );
        INSERT tUser; 
                             
    }
    
    testMethod
    static void execCaseCommentDelete1(){
    test.startTest();
     
    createTestData1();
    
       try{
           System.runAs(tUser)
            {
             DELETE tComment;
            }
          }
       catch(Exception e){ }
       test.stopTest();
    }    
// End of Test 1


    
// Start of Test 2    
    static void createTestData2(){
        tCase = new Case();
        tCase.Status = 'Open';
        tCase.Description = 'Test Description-2 ';
        tCase.Origin = 'Annuity External';
        tCase.Type = 'Feature Request';
        tCase.Priority = 'Low';
        INSERT tCase;
        
        tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Some Comment-2';
        tComment.IsPublished = TRUE;
        INSERT tComment;
        
        tProfile = 
            [
                SELECT Id 
                FROM   Profile 
                WHERE  Name = 'Prod IT Support User'
            ];
            
        tUser = new User(
            Alias = 'standt2', 
            Email='standarduser2@testorg.com', 
            EmailEncodingKey='UTF-8', 
            LastName='Testing', 
            LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', 
            ProfileId = tProfile.Id, 
            TimeZoneSidKey='America/Los_Angeles', 
            UserName='testuser2@sometestorg.com',
            Non_Use_Send_Deactivation_Alert__c=FALSE,
            DefaultCurrencyIsoCode='USD',
            CurrencyIsoCode='USD',
            ReceivesAdminInfoEmails=FALSE,
            ByPass_New_Hire_Welcome__c=TRUE
        );
        INSERT tUser; 
                             
    }
    
    testMethod
    static void execCaseCommentDelete2(){
    test.startTest();
     
    createTestData2();
            
    // Query your permission set name from Organization that your want to test.
       PermissionSet PS2 = [SELECT Id FROM PermissionSet WHERE Name = 'Super_User'];
       PermissionSetAssignment PSA2=new PermissionSetAssignment
       (AssigneeId = tUser.Id,PermissionSetId = PS2.Id); 
                       
       try{
           System.runAs(tUser)
            {
             insert PSA2; 
              System.debug('****testPS2....'+PS2);
              DELETE tComment;
            }
          }
       catch(Exception e){ }
       test.stopTest();
    }    
// End of Test 2
    
}
 

 

 

 

 

Hello,

I want to warn CASE users if they have entered an external email address in the CASE.ToAddress or CASE.CcAddress when the hit the SEND button. I was thinking a Validation Rule might work, but one valid internal email address blows that idea.

I am thinking a trigger might provide a better solution? Something like...


If(:CASE.ToAddress. NOT Contains("@MyCompany.com")
   ALERT("Hey, you cannot send a CASE email outside                   MyCompany.com")

 
Any suggestions?


Thanks SF Fam!


Robert

Hello all,

I have a Before Update trigger that is working mostly correct. I have added a custom field to User called Send_Deactivation_Alert__c (SDA).

I want the Admin to check the SDA box when a user has not signed on in a long time. I want my trigger to load 2 other fields when the SDA box is checked.

My problem is as soon as I open the User record the SDA gets checked somehow...is this becuse I am using Before Update?

 

trigger Load_Custom_User_Fields_Trigger on User (before update) {
for(User u:trigger.new){
    if (u.Send_Deactivation_Alert__c=TRUE){ 
      u.Last_Login_for_PB_Flows__c = u.LastLoginDate;
      u.Managers_Email_for_PB_Flows__c =         u.Managers_Email_del__c;
      }
    }
}

 

Hello,

I have a simple trigger to update a few custom fields on the User Profile Object. Not sure what is missing...I want my trigger to fire when the User Profile is updated.

Thanks for your help!

 

trigger Update_User_Custom_Fields_Trigger on User (before insert, before update) {
for(User u:trigger.new){
u.Last_Login_for_PB_Flows__c = u.LastLoginDate;
u.Managers_Email_for_PB_Flows__c = u.Managers_Email_del__c;
u.AboutMe = '*** This is a Test ***'
}
}

 

Hello all,

I have very simple trigger that loads a custom field  NewLead.NetNewLead__c=TRUE when a Lead is Cloned.

trigger Load_Cloned_NetNewLead_Trigger on Lead (before update) {
    for (Lead NewLead : Trigger.new) {
        if (NewLead.isClone() ){
          NewLead.NetNewLead__c=TRUE;
        }
    }
}

 

I am unable to write a test class to meet code coverage requirement. How do I simulate a Cloned Lead?

Thanks for your help.

 

@isTest
private class Load_Cloned_NetNewLead_TriggerTest {

static testMethod void testEx(){
        
Test.startTest();
        
 Account a = new Account(
 Name ='test 1', Industry='Academia', SI_Type__c='Prospect',           BillingCountry='United States');
 insert a; 
     Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Business_Contact').getRecordTypeId();
 

//CREATE CONTACT      
 Contact c=new Contact(
  FirstName='fname',recordtypeid ='0121A0000007rgsQAA',
  LastName = 'lname', accountid = a.Id , 
  Email = 'Test_002.email@gmail.com',
  Clinical_Services__c = True,
  Phone = '9743800309'); 
  insert c; 
 

//CREATE 1ST LEAD                  
Lead l = new Lead(FirstName='FirstName-Test1', LastName='LastName-Test1', Company='Company-Test1', Status='Untouched' , Email='Test_001.email@gmail.com', Industry='Academia' ,LeadSource='Advertising(Online)', Almac_Division__c='CS', NetNewLead__c=TRUE );
insert l ;

//CREATE 2ND LEAD        
Lead l1 = new Lead(FirstName='FirstName-Test2', LastName='LastName-Test2', Company='Company-Test2', Status='Untouched', Email='Test_002.email@gmail.com', Industry='Academia' ,LeadSource='Advertising(Online)', Almac_Division__c='CS', NetNewLead__c=FALSE );
insert l1 ;
    
//ATTEMPT TO CLONE LEAD???       
l1.FirstName='FirstName-Test3';
l1.LastName='LastName-Test3';
l1.Company='Company-Test3';
l1.Status='Untouched';
update l1 ;
System.assertEquals(true, l1.isClone());
        
Test.stopTest();
    }
    }

 

 

Hello all,

I have a Before Insert Trigger on Leads object. On my Leads object I have a custom field, NetNewLead with a default value of TRUE.

My trigger checks the Contacts object looking for a match on Leads.Email = Contacts.Email and when a match is found NetNewLead is set to FALSE.

My trigger works correctly when I enter a new Lead, however Web-To-Lead always sets my custom field NetNewLead to FALSE even when the Leads.Email is not found as a Contacts.Email.

Any ideas? I have includded my code if you would like to take a look.

* I know I need to remove hard-coded check for RecrdTypeId.

Thanks for your help in advance.

Robert.


trigger Update_NetNewLead_Trigger on Lead (before insert) {

// Step 1 - Iterate over incoming Leads and store email in a set
    List<String> leadEmails = new List<String>();
    for(Lead lead:Trigger.new){
        leadEmails.add(lead.Email);
    }

// Step 2 - Check whether there are any existing Business Contacts with matching email

    //Id RecordTypeIdContact = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Business_Contact').getRecordTypeId();

    List<Contact> contacts = [
        SELECT 
            Id, Email 
        FROM 
            Contact
        WHERE 
            //Email IN :leadEmails and RecordTypeId=:RecordTypeIdContact 
            Email IN :leadEmails and RecordTypeId='0121A0000007rgsQAA'
            // Only Select "Business Contacts" 
    ];

    Set<String> contactEmails = new Set<String>();
    for(Contact contact:contacts){
        contactEmails.add(contact.Email);
    }

// Step 3 - Iterate over Leads if Business Contact has matching email set NetNewLead = False
    for(Lead lead:Trigger.new){
        if(contactEmails.contains(lead.Email)){
            lead.NetNewLead__c = False;
        }
    }
}

 

So...I created a simple trigger to Update a custom Lead field. I need help creating a test class for my trigger...someone please help.

With thanks in advance.

Robert

Here's the trigger:

 

trigger Update_NetNewLead_Trigger on Lead (before insert) {

// Step 1 - Iterate over incoming Leads and store email in a set
    List<String> leadEmails = new List<String>();
    for(Lead lead:Trigger.new){
        leadEmails.add(lead.Email);
    }

// Step 2 - Check whether there are any existing Business Contacts with matching email
    List<Contact> contacts = [
        SELECT 
            Id, Email 
        FROM 
            Contact
        WHERE 
            Email IN :leadEmails and RecordTypeId='0121A0000007rgsQAA'
            // Only Select "Business Contacts" 
    ];

    Set<String> contactEmails = new Set<String>();
    for(Contact contact:contacts){
        contactEmails.add(contact.Email);
    }

// Step 3 - Iterate over Leads if Business Contact has matching email set NetNewLead = False
    for(Lead lead:Trigger.new){
        if(contactEmails.contains(lead.Email)){
            lead.NetNewLead__c = False;
        }
    }
}

Hi All,

I am trying to update a custom field (NetNewLead__c) when a Lead's Email doesn't exist in Contact Email.

I am thinking a Trigger is the best solution, but my Apex skills are lacking.

I do not want to prevent creation of the Lead.

Can someone take a look at my code and offer advice?

Kind regards,

Robert

Code is below

trigger NetNewLead_Trigger on Lead (after update) {
    class UniqueKey {
        UniqueKey(String email) {
        this.email = email;
        }
        string Email;
        integer hashCode() {
            return toString().hashCode();
        }
        boolean equals(Object o) {
            return toString() == ((UniqueKey)o).toString();
        }
        public override string toString() {
            return String.format(
                'Email = \'\'{0}\'\'',
                new String[] {
                Email==null?'':String.escapeSingleQuotes(Email.tolowercase())
                }
            );
        }
    }

    Map<UniqueKey, Lead> leads = new Map<UniqueKey, Lead>();
    for(Lead record:Trigger.new) {
        if(record.isconverted) {
            UniqueKey key = new UniqueKey(record.email);
            if(leads.containskey(key)) {
                record.addError('Duplicate lead conversion.');
            } else {
                leads.put(key, record);
            }
        }
    }
    String[] keys = new String[0];
    for(UniqueKey key:leads.keyset()) {
        keys.add(key.tostring());
    }
    String query = string.format(
        'SELECT Id,Email,RecordTypeId FROM Contact WHERE RecordTypeId =:Client Contact" and {0}',
        new String[] {
            String.join(keys, ' OR ')
        }
    );
    if(!leads.isempty()) {
        for(Contact record:Database.query(query)) {
            UniqueKey key = new UniqueKey(record.email);
            if(leads.containskey(key)) {
                leads.get(key).addError('Duplicate lead conversion.');
            }
        }
    }

}

Hello all,

So I created a trigger to Cases in a queue, when size is reached I want to send an email once..only once.

My trigger is firing at limit (3), but is sending the email 3 times. I think I need a second or third set of eyes to see what I am missing.

Thanks for your help.

Robert 

trigger NotificationExceedingQueueLimit3 on Case (before insert,before update) {

boolean EmailSent = False;

    list<group> queuelist= [SELECT id  FROM Group where DeveloperName = 'CPS_Default_Queue'and Type = 'Queue' limit 1];     
    if(queuelist.size()>0){
                
             list<case> caselist = [select id from case where ownerid =:queuelist[0].id];
             for(case cs : trigger.new){
             
                if(caselist.size()==3 && EmailSent == False)
                {
                  EmailSent = True; 
                  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
                  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                  List<String> sendTo = new List<String>();
                  sendTo.add('Hello.Friend@gmail.com' );
                  mail.setHtmlBody('Hello, <br/> Default Queue Limit Exceeded. The count has exceeded 2 cases.<br/><br/> Thanks, <br/>Salesforce Admin');
                  mail.setSubject('Case Limit of 02 Exceeded');
                  mail.setToAddresses(sendTo);
                  mails.add(mail);   
                  Messaging.sendEmail(mails); 
                }
        
             }
    }  
}
 

 

 

Hello all,

So I created a trigger to Cases in a queue, when size is reached I want to send an email once..only once.

My trigger is firing at limit (3), but is sending the email 3 times. I think I need a second or third set of eyes to see what I am missing.

Thanks for your help.

Robert 

trigger NotificationExceedingQueueLimit3 on Case (before insert,before update) {

boolean EmailSent = False;

    list<group> queuelist= [SELECT id  FROM Group where DeveloperName = 'CPS_Default_Queue'and Type = 'Queue' limit 1];     
    if(queuelist.size()>0){
                
             list<case> caselist = [select id from case where ownerid =:queuelist[0].id];
             for(case cs : trigger.new){
             
                if(caselist.size()==3 && EmailSent == False)
                {
                  EmailSent = True; 
                  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
                  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                  List<String> sendTo = new List<String>();
                  sendTo.add('Hello.Friend@gmail.com' );
                  mail.setHtmlBody('Hello, <br/> Default Queue Limit Exceeded. The count has exceeded 2 cases.<br/><br/> Thanks, <br/>Salesforce Admin');
                  mail.setSubject('Case Limit of 02 Exceeded');
                  mail.setToAddresses(sendTo);
                  mails.add(mail);   
                  Messaging.sendEmail(mails); 
                }
        
             }
    }  
}
 

 

 

Hello All,

I have a simple trigger, PreventCCDeletion that should only allow Users with Profile='System Administrator-2012' or with Permission Set='Super User'  to delete Case Comments. The trigger works well...unfortunately I cannot reach the proper Code Coverage and cannot get over 66%.

Thanks in advance for your help.

Kned regards,

Robert

User-added image

Here is my trigger:

trigger PreventCCDeletion on CaseComment (before delete) {

Boolean YouCanDelete;
YouCanDelete=FALSE; 

    for(CaseComment cc : trigger.old)
    {
       
    // Check for 'System Administrator-2012' Profile
    
      List<Profile> PROFILE = [SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId() LIMIT 1];
      String MyProfileName = PROFILE[0].Name;
      If (MyProfileName=='System Administrator-2012'){ 
        YouCanDelete=TRUE;
      }
    
   
     // Check for 'Super User' ( 0PS0y000000D0dvGAC ) Permission Set
     
     If (YouCanDelete=FALSE){
        List<PermissionSetAssignment> SUPERUSER = [SELECT PermissionSet.Name FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'Super_User' LIMIT 1];
        String MyPermissionName = SUPERUSER[0].PermissionSet.Name;
          If (MyPermissionName=='Super_User'){   
          YouCanDelete=TRUE;
        }
      }
  
      If (YouCanDelete=FALSE) 
      { 
        cc.adderror('Case Comments cannot be deleted');
      }
    } 
}
 

Here is my test class:

@isTest
public class PreventCCDeletion_Test{
    
    static Case tCase;
    static CaseComment tComment;
    static Profile tProfile;
    static User tUser;
    
// Start of Test 1    
    static void createTestData1(){
        tCase = new Case();
        tCase.Status = 'Open';
        tCase.Description = 'Test Description-1 ';
        tCase.Origin = 'Annuity External';
        tCase.Type = 'Feature Request';
        tCase.Priority = 'Low';
        INSERT tCase;
        
        tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Some Comment-1';
        tComment.IsPublished = TRUE;
        INSERT tComment;
        
        tProfile = 
            [
                SELECT Id 
                FROM   Profile 
                WHERE  Name = 'System Administrator-2012'
            ];
            
        tUser = new User(
            Alias = 'standt', 
            Email='standarduser@testorg.com', 
            EmailEncodingKey='UTF-8', 
            LastName='Testing', 
            LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', 
            ProfileId = tProfile.Id, 
            TimeZoneSidKey='America/Los_Angeles', 
            UserName='testuser@sometestorg.com',
            Non_Use_Send_Deactivation_Alert__c=FALSE,
            DefaultCurrencyIsoCode='USD',
            CurrencyIsoCode='USD',
            ReceivesAdminInfoEmails=FALSE,
            ByPass_New_Hire_Welcome__c=TRUE
        );
        INSERT tUser; 
                             
    }
    
    testMethod
    static void execCaseCommentDelete1(){
    test.startTest();
     
    createTestData1();
    
       try{
           System.runAs(tUser)
            {
             DELETE tComment;
            }
          }
       catch(Exception e){ }
       test.stopTest();
    }    
// End of Test 1


    
// Start of Test 2    
    static void createTestData2(){
        tCase = new Case();
        tCase.Status = 'Open';
        tCase.Description = 'Test Description-2 ';
        tCase.Origin = 'Annuity External';
        tCase.Type = 'Feature Request';
        tCase.Priority = 'Low';
        INSERT tCase;
        
        tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Some Comment-2';
        tComment.IsPublished = TRUE;
        INSERT tComment;
        
        tProfile = 
            [
                SELECT Id 
                FROM   Profile 
                WHERE  Name = 'Prod IT Support User'
            ];
            
        tUser = new User(
            Alias = 'standt2', 
            Email='standarduser2@testorg.com', 
            EmailEncodingKey='UTF-8', 
            LastName='Testing', 
            LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', 
            ProfileId = tProfile.Id, 
            TimeZoneSidKey='America/Los_Angeles', 
            UserName='testuser2@sometestorg.com',
            Non_Use_Send_Deactivation_Alert__c=FALSE,
            DefaultCurrencyIsoCode='USD',
            CurrencyIsoCode='USD',
            ReceivesAdminInfoEmails=FALSE,
            ByPass_New_Hire_Welcome__c=TRUE
        );
        INSERT tUser; 
                             
    }
    
    testMethod
    static void execCaseCommentDelete2(){
    test.startTest();
     
    createTestData2();
            
    // Query your permission set name from Organization that your want to test.
       PermissionSet PS2 = [SELECT Id FROM PermissionSet WHERE Name = 'Super_User'];
       PermissionSetAssignment PSA2=new PermissionSetAssignment
       (AssigneeId = tUser.Id,PermissionSetId = PS2.Id); 
                       
       try{
           System.runAs(tUser)
            {
             insert PSA2; 
              System.debug('****testPS2....'+PS2);
              DELETE tComment;
            }
          }
       catch(Exception e){ }
       test.stopTest();
    }    
// End of Test 2
    
}
 

 

 

 

 

Hello all,

I have a Before Update trigger that is working mostly correct. I have added a custom field to User called Send_Deactivation_Alert__c (SDA).

I want the Admin to check the SDA box when a user has not signed on in a long time. I want my trigger to load 2 other fields when the SDA box is checked.

My problem is as soon as I open the User record the SDA gets checked somehow...is this becuse I am using Before Update?

 

trigger Load_Custom_User_Fields_Trigger on User (before update) {
for(User u:trigger.new){
    if (u.Send_Deactivation_Alert__c=TRUE){ 
      u.Last_Login_for_PB_Flows__c = u.LastLoginDate;
      u.Managers_Email_for_PB_Flows__c =         u.Managers_Email_del__c;
      }
    }
}

 

Hello,

I have a simple trigger to update a few custom fields on the User Profile Object. Not sure what is missing...I want my trigger to fire when the User Profile is updated.

Thanks for your help!

 

trigger Update_User_Custom_Fields_Trigger on User (before insert, before update) {
for(User u:trigger.new){
u.Last_Login_for_PB_Flows__c = u.LastLoginDate;
u.Managers_Email_for_PB_Flows__c = u.Managers_Email_del__c;
u.AboutMe = '*** This is a Test ***'
}
}

 

Hello all,

I have very simple trigger that loads a custom field  NewLead.NetNewLead__c=TRUE when a Lead is Cloned.

trigger Load_Cloned_NetNewLead_Trigger on Lead (before update) {
    for (Lead NewLead : Trigger.new) {
        if (NewLead.isClone() ){
          NewLead.NetNewLead__c=TRUE;
        }
    }
}

 

I am unable to write a test class to meet code coverage requirement. How do I simulate a Cloned Lead?

Thanks for your help.

 

@isTest
private class Load_Cloned_NetNewLead_TriggerTest {

static testMethod void testEx(){
        
Test.startTest();
        
 Account a = new Account(
 Name ='test 1', Industry='Academia', SI_Type__c='Prospect',           BillingCountry='United States');
 insert a; 
     Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Business_Contact').getRecordTypeId();
 

//CREATE CONTACT      
 Contact c=new Contact(
  FirstName='fname',recordtypeid ='0121A0000007rgsQAA',
  LastName = 'lname', accountid = a.Id , 
  Email = 'Test_002.email@gmail.com',
  Clinical_Services__c = True,
  Phone = '9743800309'); 
  insert c; 
 

//CREATE 1ST LEAD                  
Lead l = new Lead(FirstName='FirstName-Test1', LastName='LastName-Test1', Company='Company-Test1', Status='Untouched' , Email='Test_001.email@gmail.com', Industry='Academia' ,LeadSource='Advertising(Online)', Almac_Division__c='CS', NetNewLead__c=TRUE );
insert l ;

//CREATE 2ND LEAD        
Lead l1 = new Lead(FirstName='FirstName-Test2', LastName='LastName-Test2', Company='Company-Test2', Status='Untouched', Email='Test_002.email@gmail.com', Industry='Academia' ,LeadSource='Advertising(Online)', Almac_Division__c='CS', NetNewLead__c=FALSE );
insert l1 ;
    
//ATTEMPT TO CLONE LEAD???       
l1.FirstName='FirstName-Test3';
l1.LastName='LastName-Test3';
l1.Company='Company-Test3';
l1.Status='Untouched';
update l1 ;
System.assertEquals(true, l1.isClone());
        
Test.stopTest();
    }
    }

 

 

Hello all,

I have a Before Insert Trigger on Leads object. On my Leads object I have a custom field, NetNewLead with a default value of TRUE.

My trigger checks the Contacts object looking for a match on Leads.Email = Contacts.Email and when a match is found NetNewLead is set to FALSE.

My trigger works correctly when I enter a new Lead, however Web-To-Lead always sets my custom field NetNewLead to FALSE even when the Leads.Email is not found as a Contacts.Email.

Any ideas? I have includded my code if you would like to take a look.

* I know I need to remove hard-coded check for RecrdTypeId.

Thanks for your help in advance.

Robert.


trigger Update_NetNewLead_Trigger on Lead (before insert) {

// Step 1 - Iterate over incoming Leads and store email in a set
    List<String> leadEmails = new List<String>();
    for(Lead lead:Trigger.new){
        leadEmails.add(lead.Email);
    }

// Step 2 - Check whether there are any existing Business Contacts with matching email

    //Id RecordTypeIdContact = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Business_Contact').getRecordTypeId();

    List<Contact> contacts = [
        SELECT 
            Id, Email 
        FROM 
            Contact
        WHERE 
            //Email IN :leadEmails and RecordTypeId=:RecordTypeIdContact 
            Email IN :leadEmails and RecordTypeId='0121A0000007rgsQAA'
            // Only Select "Business Contacts" 
    ];

    Set<String> contactEmails = new Set<String>();
    for(Contact contact:contacts){
        contactEmails.add(contact.Email);
    }

// Step 3 - Iterate over Leads if Business Contact has matching email set NetNewLead = False
    for(Lead lead:Trigger.new){
        if(contactEmails.contains(lead.Email)){
            lead.NetNewLead__c = False;
        }
    }
}

 

Hi All,

I am trying to update a custom field (NetNewLead__c) when a Lead's Email doesn't exist in Contact Email.

I am thinking a Trigger is the best solution, but my Apex skills are lacking.

I do not want to prevent creation of the Lead.

Can someone take a look at my code and offer advice?

Kind regards,

Robert

Code is below

trigger NetNewLead_Trigger on Lead (after update) {
    class UniqueKey {
        UniqueKey(String email) {
        this.email = email;
        }
        string Email;
        integer hashCode() {
            return toString().hashCode();
        }
        boolean equals(Object o) {
            return toString() == ((UniqueKey)o).toString();
        }
        public override string toString() {
            return String.format(
                'Email = \'\'{0}\'\'',
                new String[] {
                Email==null?'':String.escapeSingleQuotes(Email.tolowercase())
                }
            );
        }
    }

    Map<UniqueKey, Lead> leads = new Map<UniqueKey, Lead>();
    for(Lead record:Trigger.new) {
        if(record.isconverted) {
            UniqueKey key = new UniqueKey(record.email);
            if(leads.containskey(key)) {
                record.addError('Duplicate lead conversion.');
            } else {
                leads.put(key, record);
            }
        }
    }
    String[] keys = new String[0];
    for(UniqueKey key:leads.keyset()) {
        keys.add(key.tostring());
    }
    String query = string.format(
        'SELECT Id,Email,RecordTypeId FROM Contact WHERE RecordTypeId =:Client Contact" and {0}',
        new String[] {
            String.join(keys, ' OR ')
        }
    );
    if(!leads.isempty()) {
        for(Contact record:Database.query(query)) {
            UniqueKey key = new UniqueKey(record.email);
            if(leads.containskey(key)) {
                leads.get(key).addError('Duplicate lead conversion.');
            }
        }
    }

}