You need to sign in to do that
Don't have an account?
Brijesh Kumar 21
roll-up summary to calculate total amount on custom object having lookup relationship with other custom object
I have two Custome Object 1. Students with having field of
1.StudentName
2.joining
3.Duration
4.TotalAmount
and another object is 2. My Courses with having field of
1.CourseName
2.FeeAmount
3.TeacherName
student object will be perent and other will child how we can calculate sum of FeeAmount to the total amount using triggerd rollup summery..
1.StudentName
2.joining
3.Duration
4.TotalAmount
and another object is 2. My Courses with having field of
1.CourseName
2.FeeAmount
3.TeacherName
student object will be perent and other will child how we can calculate sum of FeeAmount to the total amount using triggerd rollup summery..
Please check once below code :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
I think I can relate this answer but I have confusion on fields that you mentioned in code which is look-up relation and where the code is making the relationship between two of them plz explain sir.
I am getting this error now.
public class RollUpTest {
static Student__c createStudent(String name, ID StudentId){
Student__c s = new Student__c();
s.Name = name;
s.S_ID__c = StudentId;
insert s;
return s;
}
static testMethod void addCourses(){
Set<Id> studentIds = new Set<Id>();
integer studentIdsOne ;
integer studentIdsTwo ;
Student__c sid1 = new Student__c();
sid1.Name = 'ZZ00034X';
insert sid1;
Student__c student1 = createStudent('Student 1',sid1.id);
Student__c student2 = createStudent('Student 2',sid1.id);
List<Course__c> CourseItems = new List<Course__c>();
for (Integer i=0;i<studentIdsOne;i++) {
Course__c CourseItem = new Course__c();
CourseItem.Name = 'LP'+i;
CourseItem.Student__c = student1.Id;
CourseItems.add(CourseItem);
}
for (Integer i=0;i<studentIdsTwo;i++) {
Course__c CourseItem = new Course__c();
CourseItem.Name = 'LP10'+i;
CourseItem.Student__c = student2.Id;
CourseItems.add(CourseItem);
}
insert CourseItems;
studentIds.add(student1.Id);
studentIds.add(student2.Id);
Map<id,Student__c> StudentMap = new Map<id,Student__c>([select Id, Name, Total_Amount__c from Student__c where Id IN :StudentIds]);
System.assertEquals(studentIdsOne,StudentMap.get(student1.Id).Total_Amount__c);
System.assertEquals(studentIdsTwo,StudentMap.get(student2.Id).Total_Amount__c);
CourseItems.get(0).Student__c = null;
update CourseItems.get(0);
Student__c student3 = [select Total_Amount__c from Student__c where Id = :student1.id];
System.assertEquals(studentIdsOne-1,Student3.Total_Amount__c);
}
}
my test class is giving assertion failed error and out of bound 0 error can you help me out with the test class sir.
i am having one standard case object on which case are created .Case object is have one lookup filed ie [parent case]
now i have to write one trigger on case object parent case should have the cout of no of child object .
can anyone please help me with this trigger?