Here is a Salesforce Apex method. I want you to modify it, so the SOQL query works even…
- User
Here is a Salesforce Apex method. I want you to modify it, so the SOQL query works even if only bundleName or sport are passed as parameters. Use the Database.query method. public static List<League__c> getLeagues(String bundleName, String sport, List countries) { List<League__c> leagues = [ SELECT Id, Name, Country__c, Language__c, ConvertedCurrency__c, Sport__c, Price__c, Is_League_Active__c FROM League__c WHERE Id IN ( SELECT League__c FROM Bundle_League__c WHERE Product_Bundle__r.Name = :bundleName ) AND Sport__c = :sport AND Country__c IN :countries AND Is_League_Active__c = TRUE ORDER BY Name ASC ]; return leagues; }
- Assistant
To modify the provided Apex method so that it works even if only
bundleNameorsportare passed as parameters, you can use dynamic SOQL by building the query string based on the parameters that are not null. Here's how you can do it:java