Can Any one help from the undelete operation iam trying 3 time to undelete only single record its working fine but when iam trying know the difference with AllRows and without Allrows to the undelete operationd
thank you Swetha but AM Already tried that public static void test_Method(){ List<Account> testacc = [Select id, Name, AnnualRevenue,Industry from Account where Industry = 'Electronics' ALL ROWS]; undelete testacc; System.debug('Accounts after undeleting'+testacc); System.debug('Accounts after size undeleting'+testacc.size()); } its showing undelete failed entity is not in the Recycle bin
The allRows parameter in the undelete method determines whether all records in the specified list of sObjects are to be undeleted, or only the records that have not been previously undeleted. When you pass allRows=true to the undelete method, all records in the specified list will be undeleted, regardless of whether they have been previously undeleted or not. When you pass allRows=false (or omit the parameter entirely), only the records that have not been previously undeleted will be undeleted. So, when you are trying to undelete only single record, you can use the allRows=false or you can simply omit it. But when you are trying to undelete all records, you need to use allRows=true to undelete all records.
List<Account> lisacc = [Select id, Name from Account where Industry = 'Electronics' ALL ROWS]; undelete lisacc;
Line: 6, Column: 1 System.DmlException: Undelete failed. First exception on row 4 with id 001Dn00000D3uOpIAJ; first error: UNDELETE_FAILED, Entity is not in the recycle bin: []
The ALL ROWS keyword queries all rows for both top level and aggregate relationships, including deleted records and archived activities.
To identify deleted records, including records deleted as a result of a merge, use the ALL ROWS parameters with a SOQL query.
Reference
If this information helps, please mark the answer as best. Thank you
public static void test_Method(){
List<Account> testacc = [Select id, Name, AnnualRevenue,Industry from Account where Industry = 'Electronics' ALL ROWS];
undelete testacc;
System.debug('Accounts after undeleting'+testacc);
System.debug('Accounts after size undeleting'+testacc.size());
}
its showing undelete failed entity is not in the Recycle bin
When you pass allRows=true to the undelete method, all records in the specified list will be undeleted, regardless of whether they have been previously undeleted or not.
When you pass allRows=false (or omit the parameter entirely), only the records that have not been previously undeleted will be undeleted.
So, when you are trying to undelete only single record, you can use the allRows=false or you can simply omit it. But when you are trying to undelete all records, you need to use allRows=true to undelete all records.
undelete lisacc
Still it was showing
undelete lisacc;
Line: 6, Column: 1
System.DmlException: Undelete failed. First exception on row 4 with id 001Dn00000D3uOpIAJ; first error: UNDELETE_FAILED, Entity is not in the recycle bin: []