You need to sign in to do that
Don't have an account?
Undertow
How do I make a SOQL query from a custom object data using apex?
How do I make a SOQL query from a custom object data using apex ?
I have custom object named News and I want to get all the added news a webpage.
This probably very simple to do, but I just couldn't find any examples or advise how to do this.
If i understand, what you want to do is to retrieve data from a custom object to show it on a page.
Try something like this
List<News__c> myNews = [Select Id, Name, myCustomField__c From News__c];
That would retrieve all the news on the news object.
you can use a Limit or Where Clause to restrict the query
List<News__c> myNews = [Select Id, Name, myCustomField__c From News__c Limit 100];
Would retrieve the first 100 rows.
List<News__c> myNews = [Select Id, Name, myCustomField__c From News__c Where Id=: myIdVariable];
Would select the new with the given id where myIdVariable is a variable of type Id containing a News Id.
Hope this helps.
Ignacio.
All Answers
If i understand, what you want to do is to retrieve data from a custom object to show it on a page.
Try something like this
List<News__c> myNews = [Select Id, Name, myCustomField__c From News__c];
That would retrieve all the news on the news object.
you can use a Limit or Where Clause to restrict the query
List<News__c> myNews = [Select Id, Name, myCustomField__c From News__c Limit 100];
Would retrieve the first 100 rows.
List<News__c> myNews = [Select Id, Name, myCustomField__c From News__c Where Id=: myIdVariable];
Would select the new with the given id where myIdVariable is a variable of type Id containing a News Id.
Hope this helps.
Ignacio.
Thank you! That was exactly what I was lookin for.