You need to sign in to do that
Don't have an account?

System.DmlException: Upsert failed. First exception on row 0; first error: STRING_TOO_LONG, password: data value too large: *** encrypted text *** (max length=15): [password__c]
System.DmlException: Upsert failed. First exception on row 0; first error: STRING_TOO_LONG, password: data value too large: *** encrypted text *** (max length=15): [password__c]
while inserting a encrypted field as password
public class newformcntrl {
public account accs{get;set;}
public string id{set;get;}
public account acc{get;set;}
Blob cryptoKey = Blob.valueOf('380db410e8b11fa9');
public newformcntrl (ApexPages.StandardController controller)
{
accs=(account)Controller.getRecord();
id=apexpages.currentpage().getparameters().get('id');
}
public pagereference savee()
{
if(accs.password__c!=null)
{
Blob data = Blob.valueOf(accs.password__c);
Blob encryData = Crypto.encryptWithManagedIV('AES128', cryptoKey , data );
String bData = EncodingUtil.base64Encode(encryptedData);
accs.password__c= bData;
Blob dta3 = EncodingUtil.base64Decode(accs.password__c);
Blob decryptedData = Crypto.decryptWithManagedIV('AES128', cryptoKey , dta3);
String dryptData = decryptedData.toString();
}
upsert accs;
pagereference p=new pagereference('/apex/newaccview?id='+acc.id);
p.SetRedirect(true);
return p;
}
}
Please check the data type for password__c.
I think it is a text field with maximum allowed characters 15. You can change the maximum value for that field.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.