• Nagaraju Mogili 22
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 0
    Replies
I have a text field "Student Marks" which allows only numbers and fixed string.( numbers >=100 and string "AB").

I have to write a validation for this.can anyone help me out with this.

Thanks in advance. 
Ex: I have 5 subject to give the marks and I should not give more than 100 marks for any subject
public class UpdateParentFields {
    public static void AfterInsert(List<Object_B__c> blist){
      List<Id> bid = new List<Id>();        
        for(Object_B__c b :blist){
             bid.add(b.Object_A__c); 
        }
    Map<Id,Object_A__c> Parentmap = new Map<Id,Object_A__c>([Select Id,End_City__c,End_Date__c,Start_City__c,Start_Date__c,(select Id,Arrive_City__c,Departure_City__c,End_Date__c,Start_Date__c from Obj_B__r) from Object_A__c where Id IN : bid]);   
               for(Object_B__c c : blist){
                Object_A__c objA = Parentmap.get(c.Object_A__c);
                      objA.Start_City__c = c.Arrive_City__c;
                      objA.End_City__c = c.Departure_City__c;
                      objA.Start_Date__c = c.Start_Date__c;
                      objA.End_Date__c = c.End_Date__c;
                   if(c.Arrive_City__c == c.Departure_City__c){
                       c.Departure_City__c.adderror('You should not select the same city for Start city and End City');
                   }
                    }
                    update parentmap.values();        
            }
    public static void AfterUpdate(List<Object_B__c> oblist){
                         List<Id> bid = new List<Id>();        
                         for(Object_B__c b : oblist){
                         bid.add(b.Object_A__c); 
             }
    Map<Id,Object_A__c> Parentmap = new Map<Id,Object_A__c>([Select Id,End_City__c,End_Date__c,Start_City__c,Start_Date__c,(select Id,Arrive_City__c,Departure_City__c,End_Date__c,Start_Date__c from Obj_B__r) from Object_A__c where Id IN : bid]);   
              for(Object_B__c objb : oblist){
                               Object_A__c objA = parentmap.get(objb.Object_A__c);
                               if(objA.End_City__c != objb.Departure_City__c){
                                   objA.End_City__c = objb.Departure_City__c;
                               }
                               if(objA.End_Date__c != objb.End_Date__c){
                                   objA.End_Date__c = objb.End_Date__c;
                       }     
                  if(objb.Arrive_City__c == objb.Departure_City__c){
                       objb.Departure_City__c.adderror('You should not select the same city for Start city and End City');
                   }
               }
            Update Parentmap.values();
         }
}