You need to sign in to do that
Don't have an account?

Make Fields Required Only Before Saving a Record
Hi Friends,
My scenario is When the owner of the record is changed.
Then for the new owner, there are some mandatory fields that the user has to be filled before saving the record.
How do i make the fields required only before saving the records.
How could i achieve this.....?
My scenario is When the owner of the record is changed.
Then for the new owner, there are some mandatory fields that the user has to be filled before saving the record.
How do i make the fields required only before saving the records.
How could i achieve this.....?
Like,
ISCHANGED(OwnerId) && ISBLANK(YOUR_Field1) && ISBLANK(YOUR_Field2)
This way, you are enforcing Validation Rule to fire whan the owner is changed.
Regards
Veenesh
trigger tname on Account (before update) {
for(account acc: trigger.new){
if(acc.ownerid != trigger.oldmap.get(acc.id).ownerid){
acc.Nachu__check__c= true;
}
if(acc.ownerid == trigger.oldmap.get(acc.id).ownerid && accnew.Nachu__check__c == true && yourfield == null){
acc.adderror('Please fill the requiredfield');
}
if(acc.ownerid == trigger.oldmap.get(acc.id).ownerid && accnew.Nachu__check__c == true && yourfield != null){
acc.Nachu__check__c= flase;
}
}
}
1. You need a way to distinct that fields become mandatroy when a certain process step or field change has ocured.
2. Then you need a validation to check whether the mandatory fiels are filled
A very basic way to achieve this:
1. Creating a reference on "Case" to a specific characteristic of the new Owner. Create a formula refering to the field using the User$ relationship.
2. Create Validation Rules on Cases. AND([new formulafield] = "VALUE", ISBLANK([Mandatory Field]))
I created a simple example. If the first name of the case owner is "Roos", then the field [Discription] should be required.
1. Formula field:
- name: Owner_First_Name
- formula: $User.First_Name
2. Validation: AND(Owner_Field_Name = "Roos", ISBLANK(Description))
Groeten,
Patrick
See the below example.
Suppose currently you have owner1 and owner2 and some fields like field1 , field2, field3.
So when owner1 changed to owner2 then field2 and field3 is required for this user.
if(ownerId == owner2){
if(field2 == null || string.isBlank(field2)){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'This field is required.'));
}
if(field3 == null || string.isBlank(field3)){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error,'This field is required.'));
}
}
You have to create the checkbox in your object. then try the below code.
trigger tname on Account (before update) {
for(account acc: trigger.new){
if(acc.ownerid != trigger.oldmap.get(acc.id).ownerid){
acc.Nachu__check__c= true;
}
if(acc.ownerid == trigger.oldmap.get(acc.id).ownerid && accnew.Nachu__check__c == true && yourfield == null){
acc.adderror('Please fill the requiredfield');
}
if(acc.ownerid == trigger.oldmap.get(acc.id).ownerid && accnew.Nachu__check__c == true && yourfield != null){
acc.Nachu__check__c= flase;
}
}
}