FAQ Tech talk introduction to apex code
Tech Talk: Introduction to Apex code Webinar FAQ
To learn more about Apex code, please visit our Apex code page on developer.force.com.
Q: Should I use Developer account or in Sandbox when testing Apex code?
A: Both. Unit Tests are not required in a Developer Edition Org but 100% code coverage is recommended. 75% code coverage is required for deploying Apex code to production from a sandbox or developer environment (org).
Q: Is there a place on the site that lists what an API call is?
A: Salesforce provides programmatic access to your organization’s information using a simple, powerful, and secure application programming interface, the Force.com Web Services API (the API). API calls represent specific operations that your client applications can invoke at runtime to perform tasks, for example:
- Query data in your organization.
- Add, update, and delete data.
- Obtain metadata about your data.
- Run utilities to perform administration tasks.
API Documentation is available on the Developer Force website
Q: What is ""strongly-typed""?
A: Each object type must be specified. Very little casting is used. See this wikipedia article. Q: Can you help me understand when to use a Visualforce solution vs. when to use an Apex Code solution? A: Visualforce is used for creating a user interface. Apex is a programming language. See An Introduction to Force.com Apex Code and An Introduction to Visualforce for more.
Q: Is the percentage of code coverage shown the actual code coverage across all lines of code in all Classes in the app? Or just in the class with which the test is associated?
A: across all
Q: I see that the List is typed -- does Apex support generics?
A: Yes, generics are supported in Apex Code.
Q: What tools are available for checking performance of code and queries? (""Explain""-type info for SOQL, for example)
A: We output performance profile information in the system log
Q: Where does the System.debug() messages go?
A: the messages are visible in debug mode. Login and select "System Log"
Q: I am building a Visualforce page. I have already created a custom object. I want to incorporate the custom object fields in my Visualforce page. Basically I would like to add a visualforce page (standard controller=mycustombojct) to the Case page layout. I get an error saying that id is incorrect
A: It should be standardController=""mycustomobject__c""
Q: I'm currently implementing a way to sign-in to an external web service from Salesforce (web tab/VF page?) and display information for this external service. Is it possible? Synchronous call outs?
A: Yes, create an Apex based Web Services callout. You can go REST or SOAP based, depending on the 3rd party WS you are trying to access. Apex based WS callouts are synchronous...you can make them asych by using @future. More information on integration can be found in the article Integrating with the Force.com Platform
Q: Which database is using by force.com
A: Oracle. See the Multitenancy Webinar for more details.
Q: Are you using standard Java annotations or customized?
A: Customized
Q: Are there examples of batched solutions/designs to avoid the governor limits?
A: Here's a great example of writing a bulkifying a trigger: http://sfdc.arrowpointe.com/2008/09/13/bulkifying-a-trigger-an-example/. The quoting example in the Apex document is another good example with some advanced idioms.
Q: Are you aware of any applications that utilize a Google App Engine front-end and Salesforce databases?
A: Take a look at the Force.com for [Google App Engine project http://developer.force.com/codeshare/apex/projectpage?id=a0630000003JyM3AAK]
Q: SVN - we have 3 developers with 3 separate DEV ORG's. What's the best way to coordinate changes between the DEV’s?
A: I'd recommend you check out using a source control system and Force.com IDE. See this blog post for more. If you join the Partner Program, you have access to an enhanced DE Org with 20 user licenses. That will allow your developers to work in the same environment.
Q: I might have missed it but WISL contracts created on the force platform can be consumed by external (non SF) applications?
A: Do you mean WSDL? If so, yes you can consume in a different environment. More information on integration can be found in the article Integrating with the Force.com Platform
Q: Any methods for persisting data to limit SOQL calls?
A: sorry no, each request has its own memory and limits
Q: Can you consume external web services using APEX code?
A: yes. More information on integration can be found in the article Integrating with the Force.com Platform
Q: can we query external databases (sql server) from SOQL?
A: Not with SOQL. You would need to create a web service and use that from Apex Code.
Q: Can a client pay to have apex functionality in professional version?
A: You can get Apex enabled in your DE org or for your application in another org by passing a security review.
Q: So if I write an apex trigger in a DE and pass your security review, I can have the trigger deployed in the professional version
A: yes BUT only for your application...and NOT for the entire org you install the app in
Q: Are there good examples of the different DML options? I've searched developer.force.com, as well as the Apex code reference PDF but haven't found great examples
A: Use data manipulation language (DML) operations to retrieve, insert, delete, and update data in a database. Search 'DML' in the Apex Developer Guide here for detailed info.
Q: How about triggers on related records? For example, in the developer guide there is the example of Account and Contacts address update. I am looking for another example to guide me where the reference to the object I want to update is on the child Object (i.e. Agreements has ContractID), but not on the parent (i.e. Contract has no AgreementID).
A: if change happens to the parent object and should fire on the children, the trigger should be on the parent, and a SOQL query would return all the children records and update those. There are samples on Developer Force.
Q: We are on enterprise - is there any tech support built in that I could avail myself to?
A: Developer Support can be purchased: See the support site, or use the discussion boards at developer.force.com
Q: If we need help beyond the examples (and we have actually *tried* reading through the examples already), what resources are available? I tried our success manager - where else could we turn?
A: developer.force.com as well as the discussion boards. There is also an instructor led course, DEV501
Q: Any suggestions for those of us who are not developers and need some help with basics such as declaring variables? I know this doesn't fit the example, so feel free to wait until a good time to address this question.
A: Start working through the developer workbook on developer.force.com. You could also try picking up some basic books on Java programming to help.
Q: Where are tests run - In sandbox or production?
A: tests are run in whichever environment you're working in or deploying to.
Q: Where can we see the current list of Apex enhancements being worked on?
A: Visit the Apex section at IdeaExchange:http://ideas.salesforce.com/popular/apex_and_visualforce - Look for the ideas that say Idea Under Consideration or Coming In The Next Release
Q: Can you explain the ""org"" structure referenced in the deploy vs. save
A: When working with salesforce.com, or the force.com platform, an 'org' refers to an organization (typically a company). In the context of application development, Apex code is saved into a development environment (typically a separate Developer Edition Org, or a Sandbox) before it can be deployed to the production org.
Q: Is there any Salesforce docs that cover building Web Services in PHP Which is the best library to use for this? The ones I have tries are producing invalid WSDL files.
A: Yes. See the PHP Toolkit on Developer Force
Q: Are there any classes in apex for parsing and creating xml data?
A: XmlStreamReader Class and XmlStreamWriter. More info in docs.
Q: Do we get any support for debugging the code, in case of developer account?
A: The discussion boards at developer.force.com are your best resource, and Developer Support can be [purchased https://www.salesforce.com/services-training/customer-support/developer-support/]
Q: Is monetary transaction like credit card processing supported using apex classes?
A: Credit Card numbers can be stored in salesforce.com and encrypted at the field level. Callouts can be made from your Apex code to 3rd party web services to process the credit card transaction.
Q: Is running WSDL require even if we don't have any web service
A: no, you don't need a WSDL if you don’t expose a Web Service...
Q: Is it possible that you don’t get any compilation issue in Apex class but deployment can point to some compilation error
A: No, at that point it would be a runtime issue.
Q: I am having issues in deploying the code that I downloaded from force.com site. Where can I get help on that?
A: Please check the discussion boards at Developer Force.
Q: Any idea when the latest version of Eclipse will be supported - 3.4.x?
A: 3.4 is coming soon.
Q: Where can I find documentation on APIs such as the WebServiceCallout class? I can't find it anywhere in the documentation online.
A: There is no class called WebServiceCallout. There are classes that allow you to make a callout to a web service. Take a look at Chapter 8 in the Apex documentation.
Q: When I write an Apex program in a new Org, is there a way for me to check which API version is that based on?
A: Yes, you can do this either in Setup or the IDE.
Q: Is there a profiling tool available to fine-tune & optimize a poorly written Apex code?
A: You can get profiling information when you execute a test for that class or when you invoke a method through the system log console. See Using the System Log console in the Apex manual.
Q: Do the governor limits remain constant, or they scale as per number of records being processed in a given context?
A: They will scale based on the number of records passed. You can learn more here.
Q: Is DISTINCT and GROUP by possible in SOQL
A: Not at this time
Q: What is deploying to server?
A: Use that command when you want to move code from a dev/sandbox org to a production org.
Q: What are SOSL and you didn’t explain much on SOSL
A: This page has a section explaining SOSL:
Q: Is Apex built on top of Java? Is Apex a 4GL built over Java?
A: Apex is a complete programming language built for the multitenant Force.com platform. The only thing you need to know is that it has syntax similar to Java - any other connection to Java is irrelevant.
Q: When you are using Force.com IDE --> difference between save to server and deploy to server
A: Save to server saves your code to the current development or sandbox environment your working. Deploy to server deploys your code to a different environment (like Production).
Q: How do you get to see compile error messages in the IDE?
A: View the ""Problems"" tab at the bottom of the IDE. (You may have to unhide it.)
Q: Can deployed classes be renamed?
A: No
Q: Are test classes for triggers stored in Salesforce?
A: yes
Q: What screen was the debug log on again?
A: click on system log link at the top of the browser
Q: is a test case only required for triggers that update the database?
A: No, for all code.
Q: maybe I missed it, but how did he get the code to the server?
A: with eclipse, the sandbox is synched with the Force.com IDE
Q: If I have a Java application, is there a way to on board that on the Force.com platform?
A: Not directly. You have to port it.
Q: What happens when the array that is returned exceeds 1,000 records? Is there a way around this limitation?
A: If the query results return more than 1,000 records, then a SOQL query for loop must be used instead, since it can process multiple batches of records through the use of internal calls to query and queryMore. Triggers have an absolute limit of 1,000 records for SOQL queries, regardless of whether the query is used in a for loop.
Q: When would you use apex code instead of an sControl?
A: Do not use s-controls. Use a combination of Apex and Visualforce rather. Existing s-controls will continue to be supported, but the ability to create new s-controls will be deprecated in a future release.
Q: where can I find instruction on how to install eclipse?
A: See Force.com IDE Installation for Eclipse_3.3.x
Q: What does the line System.debug(i); do?
A: Debug creates a log entry much like System.out.print() in Java.
Q: Is there built-in support for other web service types, such as REST?
A: you can call REST services from Force.com - see Apex language reference as well as other article on developer.force.com
Q: what about *exposing* data via REST? that is, there was a ""generate WSDL"" button for classes defined as ""webservice""
A: to expose using a REST format, you would write a visualforce page that read its query string params, and then respond with XML output
Q: is there a built-in way to write tests for triggers?
A: test methods can insert records; this causes the trigger to be tested.
Q: Can a Sybase database be queried via Apex?
A: Not directly, you would need to expose a web service that performs the query or build an integration with the web services API
Q: I need to run tests on a trigger to move to production. You touched on it briefly but I did not understand how to create tests and comply with the 75% rule. What was your reference?
A: This article provides a good reference: An Introduction to Apex Code Test Methods
Q: is there any example to use sql server?
A: Apex code does not directly connect to 3rd party databases. Integration between 3rd party databases and Force.com is common however.
Q: how many records will be limit per hit
A: here is more information on governor limits from the tech docs
Q: can we use exception handling?
A: yes with try {} catch {}
Q: Can we send and retrieve data to and from force.com to SQL server?
A: Yes via the web services API. We have partners that have built integration tools also. Check out appexchange.com.
Q: When you upgrade, should we assume that the existing codes would work with the new version?
A: Yes - when we release new versions of the platform, your existing Apex Code will continue to work as it is compiled to a specific version of the runtime.
Q: How do we integrate enterprise SOR like SAP with force.com and is there a way to do it real time?
A: there is a native SAP connector: http://www.salesforce.com/platform/integration/
Q: What versions of eclipse are supported
A: The IDE supports version 3.2 and 3.3. 3.4 may be coming
Q: is it possible to use C# to access force.com
A: yes, using our web services api: http://wiki.developerforce.com/index.php/Web_Services_API#API
Q: Any considerations for building apps for different editions of salesforce customers?
A: You can use this edition chart to determine the functionality customers on each edition have access to:
Q: Are insert triggers executed when performing dataload via dataloader?
A: Yes.
Q: Can Apex code trigger an insert into another related object from a parent object?
A: yes, this is quite possible to build in a trigger
Q: Is it possible to run individual tests from the IDE (as opposed to all tests) or is that only possible in the Web interface
A: yes you can, right click on the file, and then you can run one-class tests
Q: My org relies on email-to-case functionality but I do not know how to use Apex with the EmailMessage object type. Is it possible to execute Apex code on incoming or outgoing emails in cases?
A: Email services are automated processes that use Apex classes to process the contents, headers, and attachments of inbound email. For example, you can create an email service that automatically creates contact records based on contact information in messages.
Q: how does my custom triggers/classes work with every release of Salesforce
A: They are compiled w/ a version number and executed against the matching version VM.
Q: can I have the test method inside my apex class?
A: yes.
Q: So, a test class is essentially an outer class containing a scripted test for specific classes?
A: It can be an external class, or it can be methods within the class being tested. See An Introduction to Apex Code Test Methods.
Q: I can't see the entire link for the ERD.
A: See here
Q: Will my code be hidden from Force.com personnel?
A: Yes, your code is like your data; we can't see it unless you explicitly allow us.
Q: can access to controllers be restricted to certain users via permissions?
A: You can specify which users can execute methods in a particular top-level class based on their user profile. Note that you can only set security on Apex classes, not on triggers.
Q: how is code coverage for unit tests determined? By method count, class count, etc?
A: code coverage is determined by the number of lines of code that are covered. See An Introduction to Apex Code Test Methods for more.
Q: On the question about customer vs. dev, is there an automated way to copy a customer's existing org to a dev org?
A: See this blog post for instructions and demo on moving / copying config and code between orgs:
Q: Does SOQL include any support for paging query results? For example, records 1001 to 2000 from a set of 10000?
A: this is planned for a future release
Q: so SOQL would query all objects in a database in just 1 hit? You would then dump it to an array?
A: Yes, as long as the number of records remained below the appropriate limit.
Q: What again are the limits for SOQL object calls in the 24hr period?
A: more information on governor limits in our tech docs here
Q: Can you execute Apex from a field validation in builder?
A: No
Q: what does .cls extension stand for?
A: Class.
Q: what is a virtual class?
A: See wikipedia
Q: Are there any published books available on Apex syntax and building force.com applications?
A: Yes. See the Books section in the Documentation
Q: where do you find the execute anonymous step in eclipse?
A: look at the bottom of the IDE. There are a series of tabs: (Problems, Apex Test Runner, Execute Anonymous, etc.)
Q: where did you store that constant ""MAX_MILES_PER_DAY"“?
A: That is a constant in the Apex class.
Q: Did I understand that right? Governor limits can be changed? Without prior notice?
A: if we were to change the governors’ limits, it would be to make those less restrictive, so your existing code should not be affected negatively
Q: Is the ForceIDE just Eclipse w/a plug-in or is it a custom version of Eclipse. Can we add the Force IDE functionality to existing Eclipse installs (if just a plug-in)?
A: yes, it's a plug-in
Q: Single or multiple inheritances?
A: single inheritance. Like Java
Q: Can interfaces & inheritance be combined?
A: Yes
Q: Is it possible to use Apex to execute a workflow on behalf of another user? Idea is to trigger an outbound email and have the system think that the record owner is the active user and not the admin.
A: A workflow gets invoked when you save a record so you can add an outbound e-mail activity as part of the workflow
Q: Is it possible to use Apex to execute a workflow on behalf of another user? Idea is to trigger an outbound email and have the system think that the record owner is the active user and not the admin.
A: Yes. System.runAs(). Documentation here and also the article An Introduction to Apex Code Test Methods
Q: how to get try catch code covered in test coverage?
A: have a look at this java-sample:
Q: what's the best practice with dealing with multiple before insert before update against a single Sobject? Should there be only 1 trigger that that object, or are multiple triggers acceptable without causing cascading effect?
A: With multiple triggers, there is no guarantee which one will fire first, so it is better to have one trigger calling multiple classes so you can select the order. One suggestion is to use a single trigger per event and use the trigger context variables like isBefore etc.
Q: For the test class, is the recommended method for organizing triggers/classes to keep things clean, easy to find, and easy to deploy?
A: the best way is to have a test class for each class, and using a simple nomenclature, such as myClass and testmyClass as names
Q: if I ADD an error then will the NEXT lines in triggers execute?
A: Look at Test.startTest and stopTest. Example/info in Apex documentation, but in addition article at An Introduction to Apex Code Test Methods
Q: can you explain why is there Limitation on Number of Query Rows (500)?
A: It is a governors limit just like the others. This prevents performance issues in multi-tenancy
Q: Can you set break points, step in, and watch the value of the variables?
A: Not at this time.
Q: I tried compiling a wsdl that had multiple bindings and received error say not allowed
A: That is correct, multiple bindings are not supported right now.
Q: Can I get a copy of PowerPoint and sample code after meeting please?
A: yes
Q: will there be any examples from a DE with person accounts enabled
A: probably not in this tech talk...that's a very specific example. But you are able to dml/query accounts (person accounts) through Apex. The primary different between a Person Account and a regular Account is its record type.
Q: So, if the code is written in a sandbox environment, we have no way of knowing if we hit any limits, until we deploy to production? Is that correct?
A: no, sandbox has the same limits
Q: How would I integrate other coding languages into SFDC, such as PHP?
A: through the web services API - you can't run other languages on Force.com. See the PHP Toolkit for example, which uses this API.
Q: How do you get Eclipse?
A: Download here at Force.com IDE
Q: Can code be obscured when deployed into production to protect the IP behind the code?
A: Yes - if you package your code in a Managed Package, the code will be hidden from the customer who installed it.
Q: how did he run the test code?
A: You can run the test in the browser under Setup or through the Force.com IDE
Q: how did he run the test code?
A: click on run tests in the test tab of eclipse, or right click on Classes | Force.com|Run All Tests (the run test button in the test tab might not be enabled and does not let you select which classes are run)
Q: Where can you update the login credentials with eclipse ide and sforce?
A: Right click the project and select Properties. There is a section on Force.com credentials there.
Q: Is there a paper on ways to integrate with other clouds or on-premises resources?
A: you might start here Integrating with the Force.com Platform
Q: Is there any limitation for objects for native applications
A: Truly Force.com applications have access to Accounts/Contacts as standard objects. You can create your own custom objects beyond that. You also have the ability to create apps on the Salesforce CRM product, which comes with other standard objects...but that won't be native, that would be an add on to Salesforce CRM
Q: What sort of instrumentation features does Apex have
A: profile info is sent to the System Log when your code is run, or when you run tests against the code
Q: Is there a plug-in for Visual Studio?
A: Nope. Not yet.
Q: can you provide a good example of when to use SOQL and when to use SOSL to illustrate their different uses?
A: See this
Q: Since test methods do not support web service callouts, how do you properly test a trigger that does a web service callout and update the record based on the returned results?
A: there is some documentation here: An Introduction to Apex Code Test Methods
Q: Can you recommend classes that we can take?
A: DEV501
Q: Would you recommend first learning Java before taking on Apex, or would that be a waste of time?
A: Go directly to Apex. Java can be useful though.
Q: If one is a SFDC admin with experience writing s-controls, but no other programming experience, can they move directly into learning apex and if so what would you recommend in terms of how to start learning it?
A: we offer classes. You could also pick up books on basic programming and Java to help. And the books in Documentation
Q: I wrote trigger to create task based on record type change account. It creates two tasks instead of one, why this happens?
A: check your logs and see if there is a field update/workflow going on. That might create the task. Also, deactivate the trigger and see if a task is generated A common error is that users write the insert statement in the wrong place, creating multiple entries
Q: Whats behavior impact with external id in trigger?
A: External ID is just a flag on a field that you can use for data integration. Triggers are attached to DML events (insert, delete etc.) so they are orthogonal.
Q: how does Apex handle concurrency and transaction control?
A: The Apex Code Language Reference provides guidance on this here
Q: If our compiled code runs in the runtime under which it was compiled, can it take advantage of new method calls without being re-compiled?
A: No, you will need to reference the new method(s) in your code, and to do that, you'll need to update the version number associated with the Apex class.
Q: After a new release, do we need to recompile our code?
A: No
Q: Sandbox vs. Production. Do you work within sandbox, THEN Deploy to Production Server?
A: yes.
Q: How will I deploy a flex app once I can no longer create scontrols? Just using HTML in a VF page and upload the .swf as a static resource?
A: Yes, use Visualforce instead of s-controls.
Q: triggers don't fire on the detail of a master/detail relationship when the master is deleted. Is there a way to make the detail trigger fire, or do I have to write a before-delete trigger on the master?
A: a trigger works on the object that is touched.if something should happen when the master is deleted, the trigger has to be on the master
Q: the ability to write scontrols is being phased-out - so this sort of functionality must be built in apex. However what if there is an scontrol, which I know, will pass the governor limits? do I just continue to do those using the api (so use the Ajax toolkit, etc) from the apex code?
A: you can use AJAX library from Visualforce as well
Q: We get timeout issues when we try to refresh Eclipse with our metadata. We have heavily customed our configuration (max custom fields for opportunities and accounts etc). How do we use Eclipse if we can't load our metadata?
A: This should be fixed with the latest version of the IDE. See here
Q: Is the developer sandbox a copy of the Customer's production environment?
A: Depends, it certainly can be.
Q: If your Apex code calls an API, and you change the API, how can you guarantee when you upgrade that the existing code will work?
A: Your code has a version associated with it, you decide when this changes. We run your code against the API specified in your file
Q: Can we schedule Apex classes to run at a particular time?
A: Not today, but there is a free app on AppExchange that can help with this. Search for CronKit
Q: Do I need to know java to learn apex?
A: No
Q: In order to stay compliant and complete unit testing required by Salesforce, how is testing monitored for each org by Salesforce? How does Salesforce enforce this requirement for up to 75% coverage?
A: The 75% code coverage constraint is enforced when you attempt to deploy your Apex code to a Production environment.
Q: Is some example of use an external web service in this webinar?
A: please refer to the online documentation for the Force.com Web Services API - there are both SOAP and REST examples
Q: Best way to learn Apex with no knowledge of Java or C#?
A: Start working through the developer workbook on developer.force.com:
Q: do you plan to add batch jobs to apex code? I.e. apex code that can be run hourly, daily, monthly, etc.
A: yes. This is probably coming
Q: what does the virtual keyword for?
A: Virtual means that the class can be extended and methods declared as public can be overridden. Similar to Abstract in Java
Q: When I try to execute a System.assert, the test fails, the test fails when the System.assert code is executed, is there some permission setting that I am missing?
A: system.assert() verifies that the parameter has a value of 'true'. If the parameter doesn't evaluate to true, the test will fail.
Q: Is the force.com platform secure enough to store billing information for recurring billing to customers?
A: Yes, the platform has several layers of security including two-factor auth and table security. See An Overview of Force.com Security
Q: Are there restrictions on Apex code with respect to licensing? In particular, what are the restrictions on an Apex class that is intended for uses who DO NOT have an Enterprise level license?
A: If this is for an app that is to be sold to Professional Edition users, the code must be packaged into a managed package, and the app itself must be reviewed by our team. Contact our partner program.
Q: How do you add apps to the production environment?
A: using appexchange packages or using the ""Deploy"" process