Hot answers tagged

4

You're allowing the attacker to use any arbitrary input, so they can inject extra parameters, etc. I think what the security scanner is looking for is EncodingUtil.urlEncode: String url = '/' + oGenericObj.getDescribe().getKeyPrefix() + '/e'; if (strObject.equals('Quote')) { url += '?oppid=' + EncodingUtil.urlEncode( System....


3

You can use the Safe Navigation Operator (?.) to avoid null checks: String someValue = inputParam?.objectHere?.someProperty; This is likely the best choice in many cases, unless you need to actually use the object for output, then you might want to go with Derek's answer.


3

I don't believe there is a way to initialize class variables without writing code to explicitly set those variables. That's not just a JSON deserialization thing, though JSON deserialization makes things just a bit more difficult because it doesn't run any constructors for the type you're using. You could turn your class variables into properties and take ...


2

for this kind of task regex is the best instrument to use. Here is a link to test regex for your needs. You can also read an explanation for regex: "(!Contract.)(.*)(?=})" 1st Capturing Group (!Contract.) !Contract matches the characters !Contract literally (case sensitive) . matches any character (except for line terminators) ...


2

I came up with the following. It is more or less an exact translation of the C# example from StackOverflow by Soner Gönül. Note that it includes a boundary for the square root of the number being checked as there is no need to check higher factors. Larger primes are going to be a challenge as divisibility by all odd numbers from 3 upward will be checked up ...


2

No, there is nothing out of the box for this requirement. You'll need to roll your own initializer.


Only top voted, non community-wiki answers of a minimum length are eligible