• sugandha arya 2
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,
my trigger is not showing error while saving  but it is dhowing error while creating new contact.I am not able to figure it out.
My requirement for trigger are:
I have one custom setting for fee structure,I have to get total fee in contact from custom setting by matching 'course__c','semester__c', 'program__c' and 'batch__c'.In contact 'course__c' and 'Program__c' are lookup fields but these fields are text data type in custom setting.On basis of matching these fields,i have to populate 'total_fee__c' in contact with custom setting field named as'total_fee__c'.
I have done with trigger.Please help me to resolve the issues.
Below is my trigger code:

//updated trigger for fee update in contact-------------->>

trigger updateFee1 on Contact (before insert, before update){
    //Get all values of custom setting in a map(Assuming that Semester is Key and Fee is value in custom setting)
    Set<String> semester=new Set<String>();
    List<Contact> course=new List<Contact>();
    Set<String> batch=new Set<String>();
    //List<Contact> program=new List<Contact>();
    course=[Select id,Courses__r.Name,Program__r.Name from Contact where id IN : Trigger.new];
    
    System.Debug('###' +course);
    for(Contact c:Trigger.new)
    {
    if(c.Term__c!=null)
    {
    semester.add(c.Term__c);
    }
    //if(c.Courses__c!=null){
    //course.add(c.Courses__c);
    //System.Debug('@@@' + course);
    //}
    if(c.Batch__c!=null){
    batch.add(c.Batch__c);
    }
    }
    //for(Id i : course){
    //String name=i.Name;
    //coursename.add(name);
    //}
     //If (semester != null &&  course[0].Courses__r.Name != null && course[0].Program__r.Name != null && batch != null){
    List<Fee_Structure__c> fee=[Select Course__c,Term__c,Batch__c,Total__c from Fee_Structure__c where Term__c IN : semester AND Course__c = : course[0].Courses__r.Name AND Batch__c IN : batch And Program__c =: course[0].Program__r.Name ];
   Map<String, Fee_Structure__c> mapfee = new Map<String, Fee_Structure__c> ();
    
    
    for(Fee_Structure__c f : fee){      
    mapfee.put(f.Term__c,f);
    }
    for(Contact c:Trigger.new){  
     if(c.Term__c!=null){
     Fee_Structure__c fees=mapfee.get(c.Term__C);
     if(fees!=null){
     c.Total_Fee_To_Be_Paid__c=fees.Total__c;
    }
    }
}
}
Hi,
my trigger is not showing error while saving  but it is dhowing error while creating new contact.I am not able to figure it out.
My requirement for trigger are:
I have one custom setting for fee structure,I have to get total fee in contact from custom setting by matching 'course__c','semester__c', 'program__c' and 'batch__c'.In contact 'course__c' and 'Program__c' are lookup fields but these fields are text data type in custom setting.On basis of matching these fields,i have to populate 'total_fee__c' in contact with custom setting field named as'total_fee__c'.
I have done with trigger.Please help me to resolve the issues.
Below is my trigger code:

//updated trigger for fee update in contact-------------->>

trigger updateFee1 on Contact (before insert, before update){
    //Get all values of custom setting in a map(Assuming that Semester is Key and Fee is value in custom setting)
    Set<String> semester=new Set<String>();
    List<Contact> course=new List<Contact>();
    Set<String> batch=new Set<String>();
    //List<Contact> program=new List<Contact>();
    course=[Select id,Courses__r.Name,Program__r.Name from Contact where id IN : Trigger.new];
    
    System.Debug('###' +course);
    for(Contact c:Trigger.new)
    {
    if(c.Term__c!=null)
    {
    semester.add(c.Term__c);
    }
    //if(c.Courses__c!=null){
    //course.add(c.Courses__c);
    //System.Debug('@@@' + course);
    //}
    if(c.Batch__c!=null){
    batch.add(c.Batch__c);
    }
    }
    //for(Id i : course){
    //String name=i.Name;
    //coursename.add(name);
    //}
     //If (semester != null &&  course[0].Courses__r.Name != null && course[0].Program__r.Name != null && batch != null){
    List<Fee_Structure__c> fee=[Select Course__c,Term__c,Batch__c,Total__c from Fee_Structure__c where Term__c IN : semester AND Course__c = : course[0].Courses__r.Name AND Batch__c IN : batch And Program__c =: course[0].Program__r.Name ];
   Map<String, Fee_Structure__c> mapfee = new Map<String, Fee_Structure__c> ();
    
    
    for(Fee_Structure__c f : fee){      
    mapfee.put(f.Term__c,f);
    }
    for(Contact c:Trigger.new){  
     if(c.Term__c!=null){
     Fee_Structure__c fees=mapfee.get(c.Term__C);
     if(fees!=null){
     c.Total_Fee_To_Be_Paid__c=fees.Total__c;
    }
    }
}
}