0

I know you can retrieve all fields from a single Object in Salesforce. I have started doing something like this:

SObjectType accountType = Schema.getGlobalDescribe().get('Account');
Map<String,Schema.SObjectField> mfields = 
accountType.getDescribe().fields.getMap();

What do I need to use to query and retrieve on all object types of all deleted records in the recycle bin?

I need to schedule a job that regularly does this in order to backup deleted records every week.

2 Answers 2

1

You will need to do a separate query for each SObject type with IsDeleted = true in the where clause: there is no "query by any type" mechanism.

There are potentially two levels of iteration:

  • Over each SObjectType (that you could get from the describe call you list or through some configuration that you set because there are probably many types that are not relevant to your business)
  • Your work will be subject to governor limits so if large numbers of records are involved you will need to break the work up into sets of records

You can probably use Batch Apex for both.

1
  • That is what I thought, that is the main problem --- by doing that I will undoubtably hit the api call limits!
    – TheAdmin
    Commented Jan 31, 2018 at 14:13
0

Retrieve the data in Recycle Bin

Create a Apex Class

public class allrows {
    public list<account> acc{set;get;}
    public allrows(){
        acc=new list<account>([select id,name from account where isDeleted = true all rows]);
    }
}

VF Page

<apex:page controller="allrows">
    <apex:pageBlock >
    <apex:pageBlockSection >
        <apex:pageBlockTable value="{!acc}" var="c"> 
        <apex:column value="{!c.name}"/>
        <apex:column value="{!c.id}"/>
        </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Or

Find all Deleted records - SELECT Id,Name FROM Account WHERE IsDeleted = true Find records with specific names - SELECT Id,IsDeleted,LastName FROM Account WHERE LastName = 'Account A'

Or

https://help.salesforce.com/articleView?id=How-to-retrieve-my-records-and-data-that-has-been-lost-or-deleted-1327108681812&language=en_US&type=1

1
  • This is specific to one object type (in your example 'Account') I need to query on all object types that have been deleted! (IsDeleted= true)
    – TheAdmin
    Commented Jan 31, 2018 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .