+ Start a Discussion
diran dsigndiran dsign 

Apex trigger to update a custom field with the combine value of three fields.How to add zero on the last field value within in the tigger.The rest of tigger working fine but only the adding zero to the last field is not working??? This is my tigger code.

trigger PopulateMemberNumber on Account (before insert) {

    List<Member_Number_Configuration__c> MN = Member_Number_Configuration__c.getAll().values();
    System.debug (MN);
    
    String zero='00000';
        
  for (Account a : Trigger.new)
  {
      
      for(Member_Number_Configuration__c tmpMn : MN)
      {
          
          if(tmpMn.City__c == a.City__c && tmpMn.Campus__c == a.Preferred_Campus__c)
          {
    
              Number StartingNumberLength = String.valueOf(tmpMn.Starting_Number__c).length();                         (show error:"Invalid number")
              Number Addzero   = zero.length()-StartingNumberLength;
                  
               a.Member_Number__c = tmpMn.City_Code__c+''+ tmpMn.Campus_Code__c+''+ (tmpMn.Starting_Number__c);
              
              break; 
          }
      }
}
}
Sri549Sri549
Hello diran,

Number zero = zero.length();
Number Addzero   = zero-StartingNumberLength;

Try like this.
Please reply me if it didnt solve.
I will may try for better solution.

Thanks
Srinivas
diran dsigndiran dsign
Hi Srinivas,

Thanks for your prompt reply.
But its still now working. :(
based on my tigger you can understand what I'm trying to do right?

Thanks 
Diran