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 

I created field email and otp in Account object.whenever i create account using email field,at taht time otp will update account object

public class UpdateOTP{
    public static void saveData(String email) {
        List<Account> accsToUpdate = new List<Account>();
       for ( Account a : [SELECT Id,OTP__c,Email__c  from Account WHERE Email__c =:email]) {
            if(a.OTP__c == null) {             
                Integer len = 5;
                Blob blobKey = crypto.generateAesKey(128);
                String key = EncodingUtil.convertToHex(blobKey);
                String pwd = key.substring(0,len);
                System.debug('OTP**** '+pwd); 
                     a.OTP__c = pwd;               
                    }
           
             accsToUpdate.add(a);
            update accsToUpdate;
                  
        }
       
    }
    }