In this post I am going to discuss Salesforce record deletion process.In Salesforce once record are deleted those records are moved to the recycle bin and they are no longer accessible through the SOQL queries or Salesforce standard views.Deleted records are maintained in the recycle bin of 15 days (earlier it was 45 but seems Salesfore has reduced the duration)
refer below link for more details
Salesforce Deleting Records
for more details about recycle bin refer
Salesforce Recycle Bin
All though normal SOQL queries do not return deleted records you can make SOQL queries include deleted records in results by adding "ALL ROWS" keyword at the end of your query.But it is important that you be careful when performing DML operations with such results because the results include deleted records.
example - using ALL ROWS in SOQL
[SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS];
In addition to above approach if you want to explicitly query deleted records only ,you can use "IsDeleted" Standard attribute.
example - using IsDeleted in SOQL
[SELECT Id, Name FROM Account WHERE IsDeleted=true];
Showing posts with label SOQL. Show all posts
Showing posts with label SOQL. Show all posts
Friday, October 17, 2014
Sunday, October 5, 2014
Salesforce SOQL Query All fields of an Object
Salesforce database query language is SOQL.When writing queries one of the tedious tasks developers face is specifying each and every field you want in queries.Unlike SQL ,SOQL doesnt allow you to query all the fields by using "*" .Salesfroce . Salesforce may have their own reasons for not allowing "*" such as querying all the fields always may affect the performance as well as it may cause you run into view state limits in visualforce pages.
All though SOQL doesn't allow you the "*" operator you can archive the same using Dynamic SOQL and the Salesforce meta data api.
Lets assume your object Name is MyObject__c
Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); Map <String, Schema.SObjectField> fieldMap = schemaMap.get('MyObject__c').getDescribe().fields.getMap(); List<MyObject__c> results; String Query = 'Select';
//loop through all object fields and add them to select clause
for(Schema.SObjectField sfield : fieldMap.Values()) { schema.describefieldresult dfield = sfield.getDescribe(); String fieldApexName = dfield.getname(); if(Query.equals('Select')) { Query+=' '+fieldApexName; } else { Query+=' ,'+fieldApexName; } }
//optionally if you want parent object fields you have to mention each of them the explicitly
Query += ',PerentObject__r.FieldName__c '; Query+= ' From MyObject__c '
//Optionally if you have a condition they can be added as
Query+= ' where Name = myfirstRecord '
//return results
results = Database.query(Query);
Learn more about Dynamic SOQL .
Learn more about SOQL
Subscribe to:
Posts (Atom)