Salesforce Q&A Part 5:
Customization Part 1:
Trigger:
Q) Explain Trigger and its flow.
Ans. Apex Triggers are event handlers. When a record associated with the trigger is inserted, updated, deleted, or un-deleted the Salesforce.com system will "fire" or execute the trigger event.
- Salesforce executes a trigger in two different contexts: before and after.
- Before-trigger events are executed before a record has been committed to the database, while after-trigger events are executed after a record is committed to the database.
- Events before/after(insert, update, delete) and after un-delete. Events helps in defining the criteria for trigger to run.
- Within the scope of trigger we define the Trigger context variable like isInsert, isUpdate, isDelete, isUndelete, isAfter, isBefore, isExecuting, new, newMap, old, oldMap and size.
- With deceive context variable we call for helper classes and pass the parameter to those classes(all logic implementation is carried here).
Q) Why use newMap and OldMap context variables in Triggers?
Ans. The newMap and oldMap contains the Id as Key and the records as value.
Q) Trigger Order of execution:
Ans.
1. The original record is loaded from the database (or initialized for an insert statement)
2. The new record field values are loaded from the request and overwrite the old values
3. System validation occurs, such as verifying that all required fields have a non-null value, and running any user-defined validation rules
4. All before triggers execute
5. The record is saved to the database, but not yet committed
6. All after triggers execute
7. Assignment rules execute
8. Auto-response rules execute
9. Workflow rules execute
10. If there are workflow field updates, the record is updated again
11. If the record was updated with workflow field updates, before and after triggers fire one more time (and only one more time)
12. Escalation rules execute
13. All DML operations are committed to the database
14. Post-commit logic executes, such as sending email.
Ans. First of all, there should not be more than one trigger per object as suggested by Salesforce.
If there are more than one trigger in the Object we have no control over the order of execution of other triggers.
Q) Difference between Odata and webservices.
Ans. OData is a protocol for building REST-based CRUD data services.
OData services deliver data in a structured format such as JSON. OData is a type of Web Service i.e. Webservice is a super and Odata/ Rest are its subset.
OData services are a type of web service just like other REST-base services.
Q) How do you expose your apex class to web-service call from other application?
Ans.
By using the Annotation
If SOAP is used Use: webservice key word in global class and its variable/method.@RestResource
(urlMapping=
'/Account/*'
).
Q) What is a Wrapper class?
Ans. Wrapper class is a container where we can add more than one datatype of records to create one virtual object for Apex functions.
Comments
Post a Comment