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
Lwc SeekarLwc Seekar 

Need Help for simple trigger using TERNARY OPERATOR

Scenario: if any of the address field is blank i would like to propulate it with text dummy using Ternary operator as if i use if else it will become lenghty.

trigger AddressFields_Insert on Lead (before insert ,before update) {
  for(Lead ld :Trigger.new )
  {

    if(Street==null|| City==null || PostalCode==null || State==null || Country==null){
     Street = 'dummy' ; 
     City= 'dummy' ; 
    PostalCode= 'dummy' ; 
    State= 'dummy' ; 
    Country= 'dummy' ; 
    }
   }                 
}   
Best Answer chosen by Lwc Seekar
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below code.
trigger AddressFields_Insert on Lead (before insert) {
    
    for(Lead ld :Trigger.new )
  {

    ld.Street = ld.Street==Null ? 'dummy' :ld.Street ;
	ld.City = ld.City==Null ? 'dummy' :ld.City ;
	ld.PostalCode = ld.PostalCode==Null ? 'dummy' :ld.PostalCode ;
	ld.State = ld.State==Null ? 'dummy' :ld.State ;
	ld.Country = ld.Country==Null ? 'dummy' :ld.Country ;
    }

}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below code.
trigger AddressFields_Insert on Lead (before insert) {
    
    for(Lead ld :Trigger.new )
  {

    ld.Street = ld.Street==Null ? 'dummy' :ld.Street ;
	ld.City = ld.City==Null ? 'dummy' :ld.City ;
	ld.PostalCode = ld.PostalCode==Null ? 'dummy' :ld.PostalCode ;
	ld.State = ld.State==Null ? 'dummy' :ld.State ;
	ld.Country = ld.Country==Null ? 'dummy' :ld.Country ;
    }

}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​
This was selected as the best answer
Lwc SeekarLwc Seekar
Thanks alot Ankaiah