Hot answers tagged

13

Switch, like the if statement, is a tool. If can do whatever switch can do and more, but it can't do what switch does as efficiently as it does. Switch can drastically reduce the complexity of some code. Just to make a point, I'm going to show you a practical, very meaningful difference. Schema.DisplayType someType = someField.getDescribe().getType(); if( ...


10

Should be something like this: %%[ if (@PromoCode == "XXXX" OR @Tier == "XXX") AND @Price == "100" then ]%% %%[ endif ]%%


7

You can create a Set that contains unique values and check if this Set contains value to check. Set<String> availableStatuses = new Set<String> { 'Dead', 'Duplicate', 'Cold' }; if(availableStatuses.contains(l.Status)) {}


6

Don't use multiple ternary operators in one line. It's way too confusing to be worth it. Here's what you have: /*condition1*/ !GWB_Utility.isNull(cust.FinancialIndicator) ? /*truthy_value1*/ /*condition2*/cust.FinancialIndicator == 'Y' ? /*truthy_value2*/ 'Yes' : /*falsy_value2*/ /*condition3*/ cust.FinancialIndicator == 'N' ? ...


6

You cannot check for multiple strings in a single variable like you did. You need to split the expression. Additionally you are missing two percent-signs for the elseif-part. So the following part: @CustomerType == ("Commercial" OR "Architect" OR "Builder") is changed to this: (@CustomerType == "Commercial" OR @CustomerType == "Architect" OR @...


5

You have two basic options: Use the Set.contains method Join complete logical clauses The first strategy would look like: Set<Integer> multiplesOf4 = new Set<Integer>{0,4,8,12,...}; for (Integer i = 0; ...) { if (multiplesOf4.contains(i)) { // do stuff } } The second strategy would look like: if (i == 0 || i == 4 || i == ...


4

It turns out that using an :if in an :iteration is not recommended. From the salesforce developer documentation: Here are some use cases where you should consider alternatives to <aura:if>: You need to nest conditional logic or use conditional logic in an iteration It is stated that this is for performance reasons, which echoes the warning ...


4

It's called ternary assignment and the syntax is: String someVariable = someBoolean ? truthyValue : falsyValue; You can see more info in Understanding Expression Operators: Operator ? : Syntax x ? y : z Description Ternary operator (Right associative). This operator acts as a short-hand for if-then-else statements. If x, a Boolean, is ...


4

Wrap it in a output panel, but to be fair itzmukeshy was correct also, you don't need to do the IF <apex:outputPanel rendered= "{!IF(yourLookup != null, true, false)}"> </apex:outputPanel>


4

You can't directly set these parent fields from the Asset record. You have to query for the related Account and set it's Actief_onderhoud_Design_Solutions__c directly. So you'll prob need to do another query on all the Account ids, put that result in a map and get the related Account that way. Also, there is no need to perform a null check here: if(...


4

Merge fields start with {! and end with }. You don't use them in the middle of a formula. To merge in the middle of the formula, you want to use the concatenation operator, &. However, doing it the way you are doing it might break on some inputs. I'd avoid possible encoding errors by using URLFOR, instead. Symbols such as &, =, and %, can cause ...


4

We use the coding convention that the curly brackets can be skipped if the condition is placed on a single line to make these common cases less cluttered looking. (Such conventions generally cause great debate though.) So in your case it would be: if (postIds.size() > 0) PostProperty(postIds); if (putIds.size() > 0) PutProperty(putIds); Your logic ...


3

Validation rules trigger when the formula evaluates to true, so I think you really just need to check that total fee is not zero and Invoiced Fee is greater than Total Fee. AND(Total_Fee__c>0, Invoice_Fee__c>Total_Fee__c) Remember, in formulas, you rarely need to use IF, because the results of AND, OR, NOT, <, >, <=, >=, <>, and != can all ...


3

Once you're in a "merge field", you don't need to keep merging: {!IF(Project.pse__Planned_Hours__c - grandtotalAH > 0, Project.pse__Planned_Hours__c - Project.Total_Billable_Hours__c, 0)}


3

For things like this, I use an array: String[] addr = new String[] { record.Street, record.City, record.State, record.PostalCode, record.Country }; for(Integer i = 4; i >= 0; i--) { if(addr[i] == null) { addr.remove(i); } } String theAddr = String.join(addr, ',');


3

It's a simple "ternary operator": String s2 = s1 != null? 'Hello': null; This is also sometimes called the "Elvis operator". The general syntax is: condition ? trueValue : falseValue; Note that both trueValue and falseValue must be the same data type (or null), and only one side or the other is evaluated (e.g. if the condition is true, the false side is ...


3

Firstly, I would use a CASE instead of IFin this case since you are always checking the same field value wrap.strdealerbaseparameter. I think that function below is more readable than what you have written. {!CASE(wrap.strdealerbaseparameter, 'Retail', objPWDUT.AI_R0_Retail__c, 'Delivery', objPWDUT.AI_R0_Delivery__c, 'Booking', objPWDUT....


3

You don't need to specify the type or name of parameters when calling methods in Apex. This: handler.OnBeforeInsert(Invoice__c record Trigger.new); Should be: handler.OnBeforeInsert(Trigger.new); Trigger.new is a list of Invoice__c records, i.e. it is of the type List<Invoice__c> which is what your method expects for the record parameter: public ...


3

"OR" means "true if either value is true". If the ID is "XXXXXXXXX", for example, it will NOT be "YYYYYYYYY", therefore OR will result in a true value. You need to use "AND" (&&) instead, meaning "true only if both values are true." Side note: It's not enough to just put an error on Trigger.new[0]; there may be multiple records in the trigger ...


3

At a first glance, I don't see anything that should be throwing a 500 error. When you are testing new functionality on a Cloudpage, it's always a good idea to wrap your scripts within a try/catch so you can get a specific (i.e. more helpful) error indicator from SFMC. <script runat="server"> Platform.Load("Core","1.1") ; try { </script> /** ...


2

Try by inserting dummy data for Source_System_Configuaration__c in test class


2

Formulas in Visualforce start with {!, and end with }. Individual fields do not start with !; using ! inside the formula works as the not operator. {!if(PP_IsOwner, $Label.D1, $Label.D2)}


2

Your syntax is a little bit all over the place. Here's how I would structure the format in a clean (easy to read), multi-line manner. Here I will change casHistory to history for my own sanity: IF( /*condition*/NOT(ISNULL(history.OldValue)), /*value_if_true*/ 'Changed ' & history.Field & ' from ' & history.OldValue & '...


2

Note: This is the current behavior, but not a guaranteed result Not sure if this is an anomaly or not as the sets are unordered but doing this seems to put it back in the order they were added. Also removes a loop. //Build the set of values Set<String> tmp = New Set<String>{'C','B',null,'A',null,'Z','D'}; System.debug(tmp); 19:19:42.23 (...


2

This is more likely to work: {!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")} if ('{!Account.OwnerId}' == '00530000006Vg2N' || {!Account.Inactive_Owner__c}) { location.replace('/flow/Inside_Account_Update_Me'); } else { alert("This Account is either not owned by Debbie or your role doesn't allow you ...


2

The accepted answer here Looping over a list of sObjects that has more than object type shows an Apex-specific extra capability of type matching that is kinda neat. Personally I'd rate a library feature like Comparator support above a language feature switch, but as I understand it, this was something of a test case to demonstrate that language enhancements ...


2

Try this: IF( AND( Department_MQL__c <> 'SDR generated, relationship management', Department_SQL__c = 'SDR', ISPICKVAL(Account.Sector__c, '<>Supplier/Distributor')), "Marketing", IF( AND( ISPICKVAL(Account.Sector__c, '<>Supplier/Distributor'), Department_MQL__c <> 'SDR generated, digital ...


2

It could be as simple as: IF(TODAY() < Start_Date__c + 364, "Base Year", "Option Year " & TEXT(FLOOR((TODAY()-Start_Date__c)/365)) ) We use the fact that subtracting two days returns a number, which we then divide by 365 and discard the fraction using FLOOR.


2

It is far easier to evaluate the conditions entirely in the formula/merge syntax, because doing so helps catch errors, is marginally less case-sensitive than using JavaScript directly, and avoids potential injection attacks if you screw something up (e.g. not JSENCODEing a string that can be updated by the user). Here's the rewrite using a formula ...


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