Giter Site home page Giter Site logo

Comments (15)

afawcett avatar afawcett commented on July 30, 2024

Take a look at this library you can do SOQL over the CustomField object and query by created date. https://github.com/afawcett/apex-toolingapi/blob/master/src/classes/ToolingAPIDemo.cls

from apex-mdapi.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 30, 2024

Hi,
using below code i displayed all custom objects with in the pageblocktable.
page:

<apex:pageBlockTable value="{!lstWrap}" var="obj" style="width:600pt">
<apex:column headerValue="Object Name" value="{!obj.objName}"/>
<apex:column headerValue="Created date" value="{!obj.dd}"/>
/apex:pageblocktable
class:
public List lstWrap {get; set;}

constructor:

List<Schema.Sobjecttype> lst = Schema.getGlobalDescribe().values();

      for(Schema.Sobjecttype s: lst){
    Schema.Describesobjectresult sobj = s.getDescribe();
     if(string.valueOf(s).contains('__c'))
     lstwrap.add(new objWrapper(string.valueOf(s));

related wrapper Class:

public class objWrapper{
public string objName{get; set;}
//public DateTime dd{get; set;}
public objWrapper(string a, string b, string c, boolean b1)
{
objName = a;
}
}

Not single object .I displayed all custom objects with in the pageblocktable. How to add created dates to wrapper class list and an display with in the pageblocktable.
help me......

    }
    objects.sort();  

}

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

The metadata API does not expose the create date. You will also have to use the tooling API to perform a SOQL query on the CustomField object to get this information and combine it into your wrapper class.

from apex-mdapi.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 30, 2024

Hi afawcett,
I try to
ToolingAPI toolingAPI = new ToolingAPI();
List<ToolingAPI.CustomObject> customObjects = (List<ToolingAPI.CustomObject>)
toolingAPI.query('Select Id, DeveloperName, NamespacePrefix From CustomObject Where DeveloperName = 'Test'').records;

Here they mensioned DeveloperName(single object name)

Give me example how to query and add to wrapper list.How to use tooling api i don't no.
help me..

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

If you take another look at the example just below the SOQL for CustomObject is a query for CustomField, you can adapt this to query all CustomField's and return the FullName and the LastModifiedDate fields. Hope this helps get the information you need to include in your wrapper classes in addition to that returned by the Metadata API already.

ToolingAPI toolingAPI = new ToolingAPI();
List<ToolingAPI.CustomField> customFields= (List<ToolingAPI.CustomField>)
   toolingAPI.query('Select FullName, LastModifiedDate From CustomField').records;
System.debug(customFields[0].fullName);
System.debug(customFields[0].lastModifiedDate);

NOTE: Please download again the ToolingAPI classes.

Also please know that you can also review the Tooling API documentation here.

from apex-mdapi.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 30, 2024

Hi afawcett,
I want to Object Created Dates not fields Created Dates

help me..........

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

Have you tried updating the last sample code i gave you to use CustomObject instead of CustomField, that probably will work?

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

Like this...

    ToolingAPI toolingAPI = new ToolingAPI();
    List<ToolingAPI.CustomObject> customObjects= (List<ToolingAPI.CustomObject>)
       toolingAPI.query('Select DeveloperName, LastModifiedDate From CustomObject').records;
    System.debug(customObjects[0].DeveloperName);
    System.debug(customObjects[0].lastModifiedDate);        

from apex-mdapi.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 30, 2024

Hi afacwcett,
I added above code like this,I got object created dates,but i con't able to add these dates to wrapper classlist..

   ToolingAPI toolingAPI = new ToolingAPI();
   List<ToolingAPI.CustomObject> customObjects= (List<ToolingAPI.CustomObject>)
   toolingAPI.query('Select DeveloperName, LastModifiedDate From CustomObject').records;

   List<Schema.Sobjecttype> lst = Schema.getGlobalDescribe().values();
    for(Schema.Sobjecttype s: lst){
          Schema.Describesobjectresult sobj = s.getDescribe();
                 if(string.valueOf(s).contains('__c'))
                lstwrap.add(new objWrapper(string.valueOf(s),sobj.customObjects[0].lastModifiedDate));//Here how to add         LastModifiedDate
     }
    objects.sort();  

Wrapper class:

 public class objWrapper{
       public string objName{get; set;}
       public DateTime dt{get;set;}
       public objWrapper(string a,DateTime d)
       {
            objName = a;
            dt=d;
       }

How to add Querying Lastmodified date to here  

   lstwrap.add(new objWrapper(string.valueOf(s),sobj.customObjects[0].lastModifiedDate));

help me.......

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

What you need to do is to create a Map from the results of the SOQL query, then use it when building your wrapper list to find the date for the approprite custom object. There is an excellent topic in the Apex developers guide on programming with Map's here, https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections_maps.htm.

from apex-mdapi.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 30, 2024

Hi afacett,
Using these methods sobj.getKeyprefix(), sobj.isQueryable()) i get all object prefixes ,query true or false .Object created dates only pending.
I try to Map<Integer, SObject> m = new Map<Integer, Sobject>(){customObjects};
i am a new in Map related concepts.
please help me......

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

Have you read the Apex Developer Guide link i sent you?

You would define the Map like this...

Map<String, ToolingAPI.CustomObject> customObjectByName = new Map<String, ToolingAPI.CustomObject>();

Then iterate over the customObjects list and populate the Map.

for(ToolingAPI.CustomObject customObject : customObjects)
    customObjectByName.put(customObject.developerName, customObjects);

Then use the Map when you are building your wrapper list.

ToolingAPI.CustomObject customObject = customObjectByName.get(String.valueOf(s));
DateTime lastModifiedDate = customObject.lastModifiedDate;

Hope this helps.

from apex-mdapi.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 30, 2024

Hi afawcett,
Thank you very much,Its working Super

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

Excellent! 👍

from apex-mdapi.

mahesh10811f0011 avatar mahesh10811f0011 commented on July 30, 2024

Hi Andrew Fawcett,
But Small problem.
Using below code i deleted objects.but permanently not deleted
public PageReference doDelete(){
MetadataService.MetadataPort service = createService();
String selectedid = System.currentPagereference().getParameters().get('p2');
List<MetadataService.Metadata> myCustomObjectList = new List<MetadataService.Metadata>();
MetadataService.CustomObject customObject = new MetadataService.CustomObject();
customObject.fullName = 'rajesh__'+selectedid+'__c';
myCustomObjectList.add(customObject);
MetadataService.AsyncResult[] results = service.deleteMetadata(myCustomObjectList);
}
When i displayed all objects in an page block table using Tooling api.All objects names come looks like below with in the pageBlock table .
DynamicForm_del
PurchaseForm_del
Master_zip_load_del
How to remove these objects permanently From Database using above code?
help me......

from apex-mdapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.