モジュール:Validation Rules  


+ [Validation Rules](https://trailhead.salesforce.com/content/learn/modules/validation-rules)
+ [Validation Rules > Implement Best Practices](https://qiita.com/Keiji_otsubo/items/c4901a6f90d8c07e4cbd)


# Get Started with Validation Rules

何もしないで検証ボタンを押してみる

:::note alert
We can’t find a Case validation rule named ‘CASE001_Engineering_Req_Numeric’.
:::


作ったけどなぁ

:::note alert
We can’t find a description on the Case validation rule named ‘CASE001_Engineering_Req_Numeric’.
:::

説明に適当に入れたけど

:::note alert
We were unable to insert a Case with a blank Engineering Req Number.
:::

最終的な入力規則

```
AND(
NOT(ISBLANK( EngineeringReqNumber__c)),
NOT(ISNUMBER(EngineeringReqNumber__c))
)
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/64dc2e59-c5e0-dcec-02dc-f1e552770004.png)


# Implement Best Practices

何もしないで検証ボタンを押してみる

:::note alert
We can’t find a Lead validation rule named ‘LEAD001_Email_Or_Phone_Required’.
:::

```
OR(
AND(
ISNEW(),
ISBLANK( Email ),
ISBLANK( Phone )
),
AND(
NOT(ISNEW() ),
ISBLANK( Email ),
ISBLANK( Phone ),
OR(
ISCHANGED(Email ),
ISCHANGED(Phone )
)
)
)
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/013d0366-4d72-740f-f8db-79a68c395915.png)

# Bypass Your Validation Rules

何もしないで検証ボタンを押してみる

:::note alert
We can’t find a Custom Permission named ‘Bypass_Case_Validation_Rules’.
:::

:::note alert
We can’t find a permission set with the ‘Bypass_Case_Validation_Rules’ custom permission.
:::

この設定がない？
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/6a2f7237-5f57-31a2-4912-5f11368d4e8e.png)


:::note alert
We were able to change a Closed case status to Working without the Bypass_Case_Validation_Rules permission.
:::

権限セットに自分を追加したけど、変わらん

:::note alert
We were able to change a Closed case status to Working without the Bypass_Case_Validation_Rules permission.
:::

TEXT(PRIORVALUE(Status)) = "Closed"
だとダメ？


```
AND(
ISCHANGED( Status),
ISPICKVAL(PRIORVALUE(Status) ,"Closed"),
NOT( $Permission.Bypass_Case_Validation_Rules )
)
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/65cad377-5f8a-1613-3788-16afa5be66dd.png)


# We can’t find a Case validation rule named ‘CASE001_Engineering_Req_Numeric’.

+ [Module Get Started with Validation Rules not finding rule](https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007eryMg)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/95c18f01-2300-df52-8e23-fc30abdd7e52.png)

:::note
Restarted browser , again, and got it to work. Browser must have had a cookie pointing to a different org. 

ブラウザを再度再起動すると、動作するようになりました。ブラウザには別の組織を指す Cookie が含まれている必要があります。
:::

# 未分類

+ [In challenge statement object name is not specified. Whether I have to create new field or any specific object I have to use](https://trailhead.salesforce.com/trailblazer-community/feed/0D5KX000000mciT)

Create a Case validation rule:

+ Rule Name: CASE001_Engineering_Req_Numeric
+ Give your validation rule a good description
+ Determine the formula to restrict the Engineering Req Number field (API name  EngineeringReqNumber__c) to numeric values if it is populated.
  + Hint: Use ISNUMBER, NOT and ISBLANK functions in your formula.

+ Error Message: Engineering Req Field must be numeric [CASE001]
+ Error Location: Engineering Req Number

:::note
Create a validation rule on the Case object

Setup --> Object Manager --> Case --> Validation Rules

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/17035d55-b1ad-abbd-aca9-b2b4dba816ed.png)
:::