You need to sign in to do that
Don't have an account?
Balajee Selvaraj
Database.update()
I have two methods in apex class called A and B.
A method have custom custom object called custom_obj.
B method hvae Standartd object called account.
If Account have dml operations dabase.update or dabase.delete, It should capture error message in exception and this error message should update in salesfoce custom_obj which is in method A.
Please answer me Freinds.
A method have custom custom object called custom_obj.
B method hvae Standartd object called account.
If Account have dml operations dabase.update or dabase.delete, It should capture error message in exception and this error message should update in salesfoce custom_obj which is in method A.
Please answer me Freinds.
Hi Balajee,
You can try with that code snippet : -
Database.SaveResult [] updateResult = Database.update(records, false);
for (Database.SaveResult r : updateResult)
{
if (!r.isSuccess())
{
for (Database.Error e : r.getErrors())
{ here you can call those custom object field from A method and assign the value : e.getMessage() }
}
}
void A(){
Custom_obj o = new Custom_obj();
0.status__c=''; //error message i have to display
}
void B(){
.............
...........
try{
database.update(listupdate);
datebase.delete(listdelete);
}catch{
}
}
public static Custom Object(API Name) A(Id AccountId, String ErrorMessage){
Custom_obj o = new Custom_obj();
o.status__c=ErrorMessage; //error message i have to display
o.Accountid = AccountId;
insert o;
}
public static void B(){
List<Database.SaveResult> updateResults = database.update(listupdate);
for (Database.SaveResult r : updateResults)
{
if (!r.isSuccess())
{
for (Database.Error e : r.getErrors())
{
Custom Object c = A(r.getId(), e.getMessage())
system.debug('aaaaa'+c);
}
}
}
}
Note : o.Accountid represent lookup field(AccountId) on custom object to associate with account. you can replace AccountId from whatever you are using ur custom lookup field api .
Thanks
Please go with that -
public static Custom Object(API Name) A(Id AccountId, String ErrorMessage){
Custom Object c = new Custom Object(AccountId = AccountId);
c.status__c=ErrorMessage; //error message i have to display
update c;
}
public static void B(){
List<Database.SaveResult> updateResults = database.update(listupdate);
for (Database.SaveResult r : updateResults)
{
if (!r.isSuccess())
{
for (Database.Error e : r.getErrors())
{
Custom Object c = A(r.getId(), e.getMessage())
system.debug('aaaaa'+c);
}
}
}
}