Your main concern shouldn't be the if statement, it's the fact that you've got a query inside a loop--if there's more than 99 shadow contacts on an account--boom, you get an uncatchable error. Realistically, this is going to work the way that will seem obvious once you see the pattern.
Map<String, Contact> contacts = new Map<String, Contact>();
That's how the API works. This is true for both REST and SOAP calls. If your software can't handle it, you need some middleware to translate the results. If you can call an executable, Salesforce CLI (SFDX) can output the query results as a CSV, which would be a flat table.
sobjList is a generic List<sObject>. The sObject class has no property Case__r, and Apex does not resolve properties like this at runtime.
The easiest way to handle this is to declare the result as a List< Staging_order__c>, so that the result of get() is an actual Staging_order__c which has the requisite properties. You could also cast the ...
Tested this with a rich text field, and the nested indentation renders in the PDF normally. If you're using the "analysis" HTML string variable like in your example, the closing LI for the "This is line number 1" list item needs to move to the end of the nested/indented UL
analysis = '<div>test data</div><div&...
This is much more easily solved with the CASE statement; this eliminates the 20+ extra parentheses you'd need, plus all of the AND operators. Here's the revised logic based on your nested bullet list:
127, 'Not Applicable',
Alternately, use the CASE function.
Here's the documentation: https://help.salesforce.com/articleView?id=customize_functions_a_h.htm&type=5#CASE
Here's the syntax: CASE(expression,value1, result1, value2,result2,...,else_result)
IF statement basically works as IF and Else in the nested if statements of yours Conditions are evaluated into the further nests if they are the condition is true/false (your case it is false).
So, Basically, if CONTAINS( Custom__Name__c , "/cs/") is evaluated to True you will be returned (String) 01u3800000NmuloAAB. no further evaluations are carried out.
Formulas are evaluated in order, which usually means from left to right. The net result is that the first condition to be met will win. For example:
IF(FALSE, 0, IF(FALSE, 1, IF(TRUE, 2, IF(FALSE, 3, IF(TRUE, 4, 5)))))
The answer will be 2, because it was the first condition to be met.
More abstractly, you can say that the conditions follow the "true path"...