Loading
Visual Studio Code Based Modeler for Consumer Goods Cloud
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Extend Validations for Framework

          Extend Validations for Framework

          Consumer Goods Cloud Mobile App Framework supports validations that check for exceptions within asynchronous Business Logic (BL) contracts. The BL contracts are validated on saving, importing, during generator calls and are manually triggered from the Implementation Backend Environment (IBE). The validation includes checking the structural correctness of the contract, validating promise chains in asynchronous BL contracts, and checking asynchronous calls in synchronous contracts.

          Required Editions

          Available in Lightning Experience in Professional, Unlimited, and Enterprise Editions that have Consumer Goods Cloud enabled.

          Steps to Prevent Error Situations in BL Contracts

          • Don’t use asynchronous calls in synchronous contracts.
          • Asynchronous contracts must return a promise. When you call an asynchronous method inside an asynchronous contract, it also returns a promise. In many cases you can return the promise of the asynchronous method as a result of the contract call. The resolve or reject function chain can be manipulated inside the contract to return contract-specific information.
          • If you must return a separate promise by your asynchronous contract, ensure that you cover all the outcomes of any asynchronous method that you call inside the contract.

          Examples of Continuous and Broken Promise Chain

          • Continuous Promise Chain: Following are the code samples for continuous promise chain in different scenarios. Returns the promise unchanged
            return someObject.doSomethingAsynchronous();
            The result is reset before the promise is resolved for extended result. Rejected promise is returned unchanged.
             return someObject.doSomethingAsynchronous().then(function(result){
             // next line converts the result into a JSON object
             return {theResult: result};
             });
            Changes the result before the promise is resolved. Rejected promise is changed to a resolved promise.
            return someObject.doSomethingAsynchronous().then(function(result){
            return {theResult: result};
            },function(error){
            return {theError: error};
            });
          • Broken Promise Chain: Following is the code sample for broken promise chain in the given scenario.

            If a new deferred is introduced, all other exceptions must be handled in the contract itself.

            var deferred = when.defer();
            someObject.doSomethingAsynchronous().then(function(result){
             // all exceptions here can NOT be handled by the framework
             deferred.resolve(result);
            }, function(error){
             deferred.reject(error);
            }).catch(fuction(error) {
             deferred.reject(error);
            });
            return deferred.promise;
           
          Loading
          Salesforce Help | Article