Download PDF
Download page Coding Guidelines and Best Practices for TurboEngines Callbacks.
Coding Guidelines and Best Practices for TurboEngines Callbacks
This section provides guidelines to follow while coding the TurboEngines compatible callbacks.
General Coding Guidelines for TurboEngines Callbacks
Guideline | Sub-topic | Description |
---|---|---|
Naming Conventions | ||
Naming a Class |
| |
Naming a Method |
| |
Naming a variable or method parameter |
| |
Naming a class property |
|
Coding Guidelines for TurboEngines Callbacks
You must follow the below guidelines while writing the callback code (C#) for TurboEngines.
Guideline | Description |
---|---|
Using Statements |
CODE
|
Namespace naming |
|
Class Naming |
|
Methods |
|
Variables |
|
Database queries related |
|
Constants |
|
Custom Fields |
|
LineItem and Proposal entity model objects |
|
Extensibility Framework Helpers | For detailed Extensibility Framework Helpers information, refer to the Helper Functions for TurboEngines Callbacks topic. |
Best Practices for TurboEngines Callback code
Consider the following practices while writing the TurboEngines compatible C# callback code.
Whenever you change specific fields within the callback code and send them to the TurboPricing for pricing, It only verifies the change in Net Price and does not verify each field to detect the difference. Hence, if you make any change in callback code that impacts pricing, perform the following.
TurboEngine uses a digest mechanism to detect if there are any changes to the line items. At the end of every pricing cycle, it recomputes the digest and compares it against the old digest. If they did not match, you could consider that the line item is changed. However, TurboEngines uses only a few selected fields (including NetPrice) to compute the digest but no custom field. Therefore, when the callback code makes any important change on a line item or custom field that TurboEngines might not detect, you must reset digest for that line item to avoid matching the new one. For example, use the following code to reset the digest for a line item with type ILineItemModel:
lineItem.Set("Digest", string.Empty);
Below is the sample pattern to be followed:
List<LineItem> lineItemsToResetDigest = new List<LineItem>();
foreach(var lineItem in allLineItems){
// business logic that changes line item's field
// add all such lines to above list
lineItemsToResetDigest.Add(lineItem);
}
// reset the digest at the end in bulk
ResetDigest(lineItemsToResetDigest);
General Practices
- Use class-level variables only when necessary and try to use the local variables as much as possible.
- If you need a class-level variable, use BeforePricingBatchAsync (Base price callback) or BeforePricingCartAdjustmentAsync (Totalling callback) methods to initialize such class level variables.
- Avoid using nested for loops.
- Do not use Try or Catch in the callback code to explicitly log any unhandled exception. By default, an unhandled exception is logged by the TurboEngine Extensibility framework. However, you can also configure to display the unhandled exception on UI using the “Is Callback Exception Throw Enabled” (is-callback-exception-throw-enabled) feature flag.
- For using Extensibility framework helpers (such as DBHelper, LogHelper, and so on) in your callback project, you must create a helper object in the callback implementation class (the main class of callback project which is implementing the callback interface). If you want to access helpers in any other supported class of your callback project, you must pass the helper instances from the main implementation class to such classes.
- You must not use the PricingHelper's UpdatePrce() method on line items unless it is necessary. Therefore, design a callback implementation that can avoid such a method call.
- Do not use concrete objects to set as a field value on the line item. In case if you want to set a concrete object as a value to the line items field, then stringify it before setting it on the line item field.
- From TurboEngine callback implementation, do not make an SFDC API call using HttpHelper in any scenario. If such a scenario needs to be handled, get in touch with TurboEngine's product or technical team.
- In Base price callback, always use batch line items for updating any value on line item as per your custom logic. Ensure that you do not update anything on cart line items when you are in the Base price callback.
- Always use the async or await pattern for each method.
- To access/update any field in callback code, the field API name/object API name must be spelled the same in Salesforce.
- Keep your code formatted for easy readability. Callback authoring UI provides code formatting capability to format the code as per C# standards.
- Keep your code to have 0 or minimum code warnings. Callback authoring UI provides the capability that shows you the code warnings per the C# standards for your callback project. Ensure that you have fixed them and incorporated them in your code to have 0 or minimum code warnings.