Deluge code error in crm function

Deluge code error in crm function

function getProductsByCategory() {
    products = zoho.crm.getRecords("Products");
    categories = {};
    for each product in products {
        category = product.get("Product Category");
        if (categories.containsKey(category)) {
            categories.get(category).add(product);
        } else {
            categories.put(category, List<JSON>.fromProduct(product));
        }
    }
    return categories;
}



_______________________________________________________________
this is the error: Failed to save the function
  • Syntax error. Expecting 'throws','sendmail','sendsms','break',function call statement,executeshellscript statement,'pushnotification',assignment statement ,'try','if','for',invokeurl statement,'return',invokeintegration statement,'continue' or 'cancel'. Found 'getProductsByCategory'. Line Number: 1