0

I am trying to write the Validation Rule OOTB or trigger to accomplish the following functionality but doesn't succeeded yet.

I have a Type field on the Child object called as Authorization, which has master detailed relationship with Case object. All VF and Controller developed are custom. On the form. Type field is created on the Authorization. and on the same form I have a related list section. When I click on new related list button then the form will open, on that form I have another field Authorization Date.

VR - When Type=Partial Refund, then AuthorizationDate is mandatory. How we can write VR or trigger to identify if its a Case form or related list form ?

When related list record will be created, if Type=Partial Refund the Authorization Date becomes mandatory.

public static void ValidationTypeCheck(List<Authorization__c> newauth, Map<Id,Case> caseMap){
    for(Authorization__c auth : newauth){

        if(caseMap.get(auth.Case__c).Type__c == 'Partial Refund'){

            if(caseMap.get(auth.Case__c).Category__c == 'Auth' && caseMap.get(auth.Case__c).SubCategory__c == 'Basic Auth'){
                System.debug('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:: '+auth.Type__c);
                if(String.isEmpty(auth.AuthrizationDate__c)){
                    auth.AuthrizationDate__c.addError('XXXXXXXXXXXX');
                }
            }
        }
    }
}

Below also doesn't works !

AND 
( 
ISPICKVAL(Case__c.Category__c, 'Auth'), 
ISPICKVAL(Case__c.SubCategory__c, 'Basic Auth'), 
ISPICKVAL(Type__c , 'Partial Refund'), 
NOT(ISNEW()), 
ISBLANK( TEXT( AuthorizationDate__c )) 
)
  • Are you creating new Authorization__c records? Because your Validation Rule does not check against new records. – Dan Kowalski Dec 4 '17 at 16:37
  • Yes, creating a Authorization__c when Case is creating and when Related List for Authorization__c also creating – Sayali Shinde Dec 4 '17 at 16:53
0

Based on what you have provided I would simply update your validation rule so that it does not exclude new records.

Not(IsNew()) to IsNew()

Your visualforce code will only check records that are not new so if you want to check certain criteria on the create you will need to open up the validation rule so that it can check newly created records as well. If you want to check on create and update then I would take out the IsNew() part of the validation rule all together.

  • Nopes, its not working... – Sayali Shinde Dec 4 '17 at 18:53
  • Have you tried to change ISBLANK( TEXT( AuthorizationDate__c )) to ISBLANK(AuthorizationDate__c )? – Dan Kowalski Dec 4 '17 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.