Validation Rule Syntax - salesforce

I have picklist with two values(A,B) and a custom field. If Values chosen other than B then the custom field should not be entered. If Value B is chosen then the custom field can be entered. What function to use. ? I m quite confused. Help Please

Something like this? I've used standard fields from Account, Rating is a picklist, ShippingCountry is text field.
Validation criteria:
ISPICKVAL(Rating, "Hot") && ISBLANK(ShippingCountry) ||
NOT(ISPICKVAL(Rating, "Hot")) && NOT(ISBLANK(ShippingCountry))
Error message:
Shipping Country is mandatory when Rating is "Hot". Please either
change the rating or clear the value in the Shipping Country field.
The condition is basically a XNOR if you're familiar with logic, simplification etc ;) But we don't have a XOR function in the functions reference.
You could also consider splitting it into 2 separate validation rules - this will let you write cleaner instructions what the user has to do "you've picked B -> fill this value!; you've picked A -> clear this value"

Using the example eyescream gave, you can further reduce the size of the condition like this:
ISPICKVAL( Rating, "Hot" ) = ISBLANK( ShippingCountry )
That is (spelled out):
if Rating is Hot and ShippingCountry is blank, then both conditions will be TRUE and equal with each other so the validation will activate and display the error
AND
if Rating is NOT Hot and Shippingcountry is NOT blank, then both conditions will be FALSE but equal with each other so the validation will activate and display the error
That type of shorter XOR expression might be handy when you have to specify a similar criteria for many fields, such as a validation that says "Shipping street, city, state and zip must be either all entered or all blank".
In such case you would enter:
ISBLANK( ShippingStreet ) != ISBLANK( ShippingCity )
|| ISBLANK( ShippingCity ) != ISBLANK( ShippingState )
|| ISBLANK( ShippingState ) != ISBLANK( ShippingPostalCode )
Notice the transitivity between each of the conditions linking the state of street to city all the way to postal code.
The expression basically means both conditions spelled out below:
if street is blank, then city should be blank and if city is blank, then state should be blank, and if state is blank, then postal code should be blank
AND
if street is NOT blank, then city should NOT be blank and if city is NOT blank, then state should NOT be blank, and if state is NOT blank, then postal code should NOT be blank

Related

How to match with common cities visited in

The goal is to match the special and the normal and the condition is that they have a common city. The special's name should appear in Column E and the Normal's name should appear in Column F and they're being matched because they both are in the same city or have visited the same city.
So the data dump that, um, will be updated on a daily basis. So for example, Type Special - Caroline has visited in Cambridge. If there's also a Type Normal that has visited Cambridge. Hence both visited Cambridge and that's why they were matched.
All right. Another example is, um, let's see here, Regina. Is a special type. Now we want to match her with a type Normal. So in this case, there are no matches, so that would not appear in the outcomes.
Only those who have been tagged as a Special or a Normal can be matched. So the match always has to be between Special and Nornal and their names just have to appear here at the visited city.
Using FILTER Function thought it would work out, that will automatically detect a Special and a Normal when there is a common keyword in a city that they visited in, but it isn't working.
GoogleSheets
try:
=QUERY(A1:D17, "select max(A),B where D is not null group by B pivot D", 1)
update:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(FILTER(A2:A17&"×"&B2:B17, D2:D17="special")&"×"&
TRANSPOSE(FILTER(A2:A17&"×"&B2:B17, D2:D17="normal"))), "×"),
"select Col1,Col3,Col4 where Col2=Col4", ))

Salesforce Validation Rule to compare value of one pick-list with other pick-list

I need to write validation rule on account, which will check valid country name from other pick list filed in exits in same object. In case that country name does not match from other country picklist then error should be displayed at account.
Thanks,
Satya
You can try the below
TEXT( Field1 ) != TEXT( Field2 )
There are several functions available to use. You can find them while creating the validation rules.

How to show entries from a referenced table in a dropdown and store the ID of the chosen entry

With two tables:
db.define_table('content',
# Here I want to store the id of the chosen layout_type
Field('layout_type_id', db.layout_type),
# Here the plain name - might not be necessary
Field('layout_type_name', 'list:string')
)
db.define_table('layout_type',
Field('layout_type_name', 'string')
)
db.content.layout_type_name.requires = IS_IN_DB(db, 'layout_type.id', '%(layout_type_name)s')
I create a form
form = crud.update(db.mytable, id)
where I want a Dropdown menu to choose a layout_type_name from - which is working - and store the id of the chosen entry.
How is it possible to store the id of the chosen layout_type_name in content.layout_type_id?
Also, if I choose one entry in the dropdown mentioned above - the (text)value is not stored when the form is successfully submitted.
These changes made this problem work:
db.define_table('content',
Field('content_type_id', db.content_type)
)
db.define_table('layout_type',
Field('layout_type_name', 'string'),
format='%(layout_type_name)s'
)
This post about record representation is exactly what I was initially looking for.

how to change the order of the filters

I was given some help on this already but I am really stuck on another part. right now the filters work in this order. the salary filter must be selected before the job title or the input filters will work. I am looking to have it setup so there is no specific order has to be used. is this possible? if not could the order change to were the input field was first and then the job title and then the salary? I tried some different ways of doing it but i could not get it to work. thank you
http://plnkr.co/edit/Kq3S51NMsgPt14sidBdo?p=preview
Currently your filter function isn't robust against the salary being undefined.
parseInt(undefined) is NaN. Even infinity >= NaN is false.
You should change your filter to this instead:
$scope.salaryFilter = function (min) {
return parseInt(min.salaryMin) >= parseInt($scope.salary_Min || 0) ;
};
The || 0 addition will replace the minimum salary with zero if it is a falsy value (i.e. null or undefined.)

Reduced Survey Frequency - Salesforce Workflow

Hoping you can help me review the logic below for errors. I am looking to create a workflow that will send a survey out to end users on a reduced frequency. Basically, it will check the Account object of the Case for a field, 'Reduced Survey Frequency', which contains a # and will not send a survey until that # of days has passed since the last date set on the Contact field 'Last Survey Date'. Please review the code and let me know any recommended changes!
AND( OR(ISPICKVAL(Status,"Closed"), ISPICKVAL(Status,"PM Sent")),
OR(CONTAINS(RecordType.Name,"Portal Case"),CONTAINS(RecordType.Name,"Standard Case"),
CONTAINS(RecordType.Name,"Portal Closed"),
CONTAINS(RecordType.Name,"Standard Closed")),
NOT( Don_t_sent_survey__c )
,
OR(((TODAY()- Contact.Last_Survey_Date__c) >= Account.Reduced_Survey_Frequency__c ),Account.Reduced_Survey_Frequency__c==0,
ISBLANK(Account.Reduced_Survey_Frequency__c),
ISBLANK(Contact.Last_Survey_Date__c)
))
Thanks,
Brian H.
Personally I prefer the syntax where && and || are used instead of AND(), OR()functions. It just reads bit nicer to me, no need to trace so many commas, keep track of indentation in the more complex logic... But if you're more used to this Excel-like flow - go for it. In the end it has to be readable for YOU.
Also I'd consider reordering this a bit - simple checks, most likely to fail first.
The first part - irrelevant to your question
Don't use RecordType.Name because these Names can be translated to say French and it will screw your logic up for users who will select non-English as their preferred language. Use RecordType.DeveloperName, it's safer.
CONTAINS - do you really have so many record types that share this part in their name? What's wrong with normal = comparison? You could check if the formula would be more readable with CASE() statement. Or maybe flip the logic if there are say 6 rec types and you've explicitly listed 4 (this might have to be reviewed though when you add new rec. type). If you find yourself copy-pasting this block of 4 checks frequently - consider making a helper formula field with it...
The second part
ISBLANK checks could be skipped if you'll properly use the "treat nulls as blanks / as zeroes" setting at the bottom of formula editor. Because you're making check like
OR(...,
Account.Reduced_Survey_Frequency__c==0,
ISBLANK(Account.Reduced_Survey_Frequency__c),
...
)
which is essentially what this thing was designed for. I'd flip it to "treat nulls as zeroes" (but that means the ISBLANK check will never "fire"). If you're not comfortable with that - you can also "safely compare or substract" by using
BLANKVALUE(Account.Reduced_Survey_Frequency__c,0)
Which will have the similar "treat null as zero" effect but only in this one place.
So... I'd end up with something like this:
(ISPICKVAL(Status,'Closed') || ISPICKVAL(Status, 'PM Sent')) &&
(RecordType.DeveloperName = 'Portal_Case' ||
RecordType.DeveloperName = 'Standard_Case' ||
RecordType.DeveloperName = 'Portal_Closed' ||
RecordType.DeveloperName = 'Standard_Closed'
) &&
NOT(Don_t_sent_survey__c) &&
(Contact.Last_Survey_Date__c + Account.Reduced_Survey_Frequency__c < TODAY())
No promises though ;)
You can easily test them by enabling debug logs. You'll see there the workflow formula together with values that are used to evaluate it.
Another option is to make a temporary formula field with same logic and observe (in a report?) where it goes true/false for mass spot check.

Resources