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
K_devK_dev 

Concatination of first letters of the fields trigger modifications

Hi 

 

My issue is my Descriptive field is getting updated from a trigger in this format

Descriptive ID

Graphic Designer-International-General-Regular-0.75
 

Required format 

 

Descriptive ID  G-I-G-R-0.75

 

Please modify this code

 

descString = '';
descString += posToUpdate.Name != NULL ? posToUpdate.Name : '' ;
descString += dbPosition.VanaHCM__Position_Title__c != NULL ? '-'+dbPosition.VanaHCM__Position_Title__c: '' ;
descString += dbPosition.Hire_Type__c != NULL ? '-'+dbPosition.Hire_Type__c: '' ;
descString += posToUpdate.Funding_Type__c != NULL ? '-'+posToUpdate.Funding_Type__c: '' ;
descString += posToUpdate.Funding_Status__c != NULL ? '-'+posToUpdate.Funding_Status__c: '' ;
descString += posToUpdate.Position_FTE__c != NULL ? '-'+posToUpdate.Position_FTE__c: '' ;
if(descString.startsWith('-') && descString.length() >0){
descString = descString.substring(1);
}
posToUpdate.Descriptive_ID__c = descString;

Best Answer chosen by Admin (Salesforce Developers) 
Grazitti InteractiveGrazitti Interactive

Hi,

 

Please modify your code as following::

 

descString = '';
descString += posToUpdate.Name != NULL ? posToUpdate.Name.left(1): '' ;
descString += dbPosition.VanaHCM__Position_Title__c != NULL ? '-'+dbPosition.VanaHCM__Position_Title__c.left(1): '' ;
descString += dbPosition.Hire_Type__c != NULL ? '-'+dbPosition.Hire_Type__c.left(1): '' ;
descString += posToUpdate.Funding_Type__c != NULL ? '-'+posToUpdate.Funding_Type__c.left(1): '' ;
descString += posToUpdate.Funding_Status__c != NULL ? '-'+posToUpdate.Funding_Status__c.left(1): '' ;
descString += posToUpdate.Position_FTE__c != NULL ? '-'+posToUpdate.Position_FTE__c: '' ;
if(descString.startsWith('-') && descString.length() >0){
descString = descString.substring(1);
}
posToUpdate.Descriptive_ID__c = descString;

 

/** if this post helps you, please throw a kudos by clicking star on left**/

 

 

Thanks

www.grazitti.com

All Answers

Grazitti InteractiveGrazitti Interactive

Hi,

 

Please modify your code as following::

 

descString = '';
descString += posToUpdate.Name != NULL ? posToUpdate.Name.left(1): '' ;
descString += dbPosition.VanaHCM__Position_Title__c != NULL ? '-'+dbPosition.VanaHCM__Position_Title__c.left(1): '' ;
descString += dbPosition.Hire_Type__c != NULL ? '-'+dbPosition.Hire_Type__c.left(1): '' ;
descString += posToUpdate.Funding_Type__c != NULL ? '-'+posToUpdate.Funding_Type__c.left(1): '' ;
descString += posToUpdate.Funding_Status__c != NULL ? '-'+posToUpdate.Funding_Status__c.left(1): '' ;
descString += posToUpdate.Position_FTE__c != NULL ? '-'+posToUpdate.Position_FTE__c: '' ;
if(descString.startsWith('-') && descString.length() >0){
descString = descString.substring(1);
}
posToUpdate.Descriptive_ID__c = descString;

 

/** if this post helps you, please throw a kudos by clicking star on left**/

 

 

Thanks

www.grazitti.com

This was selected as the best answer
hamshuhamshu

You can Try something Like this also,

 

trigger Concatinationoffirstletters  on Account (Before insert,before update) 
{
   
    list<account> accounttoupdate =new list<account>();
    for(account acc:Trigger.new)
    {
        String s1 = acc.Name;
        String s2 = s1.left(1);
        String s3 = acc.Contact_Names__c;
        String s4 = s3.left(1);
        String s5 = acc.Rating;
        String s6 = s5.left(1);
        String s7 = acc.Type;
        String s8 = s7.left(1);
        acc.ABC__c=s2+'-'+s4+'-'+s6+'-'+s8;
        system.debug(acc.ABC__c);
    }
    
}

Thanks,

jaba