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
MUSFAR KT 6MUSFAR KT 6 

prefix first name with Dr when new lead is created or updated.

trigger Prefix_Dr on Lead (before insert,before update) {
    for(lead L:trigger.new){
       L.FirstName='Dr.'+L.FirstName;
        }
}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@istest
public class Prefix_Dr_test {
    testmethod static void test(){
        Lead L=New Lead();
        L.FirstName='Dr.Midul';
        L.LastName='ahmed';
        L.Company='sfdc';
        L.Status='Working-contacted'; 
        insert L;
        
        Lead Le=[select Id,firstname,lastname from lead where company='sfdc'];
       System.assertEquals(Le.FirstName.ContainsIgnoreCase('Dr.'),'Dr.');
           
    }


here test class is showing error
Best Answer chosen by MUSFAR KT 6
Naveen KNNaveen KN
Hi Musfar, found the issue. 

System.assertEquals(Le.FirstName.ContainsIgnoreCase('Dr.'),'Dr.'); In this line of code, first parameter is boolean, hence you need to make changes as below. 

System.assertEquals(Le.FirstName.ContainsIgnoreCase('Dr.'), true);

test this and let us know the outcome. 

Naveen
Team codengine.in 

All Answers

Naveen KNNaveen KN
Hi Musfar, 

what is the error you are seeing? add more details if you still facing the issue. 

Naveen
Naveen KNNaveen KN
Hi Musfar, found the issue. 

System.assertEquals(Le.FirstName.ContainsIgnoreCase('Dr.'),'Dr.'); In this line of code, first parameter is boolean, hence you need to make changes as below. 

System.assertEquals(Le.FirstName.ContainsIgnoreCase('Dr.'), true);

test this and let us know the outcome. 

Naveen
Team codengine.in 
This was selected as the best answer
MUSFAR KT 6MUSFAR KT 6
Thanks for support
Project RequirementsProject Requirements
Hi @MUSFAR KT 6 ,

I tried solving the trigger below way . I am  new joiner in salesforce please let me know your suggestions @Naveen KN you've solved it amazingly.
--->
  trigger Assignment17 on Lead (before insert, before update)
{
    if(trigger.isbefore &&(trigger.isInsert || trigger.isUpdate))
{
       for(lead Ld:trigger.new)
{
        Ld.FirstName='Dr'+''+Ld.FirstName;
    }
    }
}

Thank You ,
Manju Bhingarkar .
bhingarkarmanju@gmail.co