You need to sign in to do that
Don't have an account?
Converting from Single Trigger to Bulk
This works fine as a single trigger. I'm new to writing bulk triggers.
How do I go about bulk-ifying this trigger?
Ben
temp_studentid = sa[0].StudentID_SIS__c;
if (temp_studentid <> null) {
temp_recordtype = 'onsite - coaching';
try {
RelatedStudentId = [select
id, Extreme_Student_ID__c
from Student__c where Extreme_Student_ID__c = :temp_studentid].id;
} catch (system.Exception e4){
}
}
//----------------------------------------------------------------
// Set fields for Updating
//----------------------------------------------------------------
sa[0].Related_School_Account__c = RelatedSchoolid;
sa[0].Related_District_Account__c = RelatedDistrictid;
sa[0].Related_Student__c = RelatedStudentid;
sa[0].Record_Type__c = temp_recordtype;
Can you plzz briefly explain what this trigger is doing, then i might be able to give you some suggestion on this.
-Sunil
Thanks!
I'm expect to do a bulk load and in order to get the info ready for analysis, I need to link each record to the appropriate objects/records upon upload.
I would like to do the following:
Any help would be great!!
Here's the entire trigger if it helps.
trigger UpdateStudentAttendance_Before on Student_Attendance__c (before insert, before update) { //--------------------------------------------------------------- // Establish variables //---------------------------------------------------------------- String saID = null, saDistrict = null, saSchool = null, saCDS = null; String RelatedSchoolId = null, RelatedDistrictId = null, RelatedStudentId = null; String temp_studentid = null, temp_recordtype = null; Integer saCDSlength = 0; Student_Attendance__c[] sa = trigger.new; saID = sa[0].Id; saDistrict = sa[0].Account_D_Code__c; saSchool = sa[0].Account_S_Code__c; saCDS = sa[0].Account_CDE_Code__c; if (saCDS <> null) { saCDSlength = saCDS.length(); } //---------------------------------------------------------------- // Update Related School and District //---------------------------------------------------------------- // If CDS code exists then parse it for the District and School Accounts if (saCDSlength == 13) { saCDS = '0' + saCDS; saCDSlength = saCDS.length(); } if (saCDSlength == 14) { saDistrict = string.valueof(saCDS.substring (2, 7)); saSchool = string.valueof(saCDS.substring (7,14)); try { RelatedDistrictid = [select id, CDS_Code__c,Account_D_code__c from Account where (Account_D_code__c = :saDistrict and Account_S_code__c = '0000000')][0].id; RelatedSchoolid = [select id, CDS_Code__c, Account_S_code__c from Account where Account_S_code__c = :saSchool][0].id; } catch (system.Exception e1) { } } // If the District code exits then parse for the District Account else if (saDistrict <> null) { try { RelatedDistrictid = [select id, CDS_Code__c,Account_D_code__c from Account where (Account_D_code__c = :saDistrict and Account_S_code__c = '0000000')][0].id; } catch (system.Exception e2) { } } else { } //---------------------------------------------------------------- // Update Related Student & Record Type //---------------------------------------------------------------- temp_studentid = sa[0].StudentID_LMS__c; if (temp_studentid <> null) { temp_recordtype = 'online - coaching'; try { RelatedStudentId = [select id, Extreme_Student_ID__c from Student__c where Extreme_Student_ID__c = :temp_studentid].id; } catch (system.Exception e3){ } } temp_studentid = sa[0].StudentID_SIS__c; if (temp_studentid <> null) { temp_recordtype = 'onsite - coaching'; try { RelatedStudentId = [select id, Extreme_Student_ID__c from Student__c where Extreme_Student_ID__c = :temp_studentid].id; } catch (system.Exception e4){ } } //---------------------------------------------------------------- // Set fields for Updating //---------------------------------------------------------------- sa[0].Related_School_Account__c = RelatedSchoolid; sa[0].Related_District_Account__c = RelatedDistrictid; sa[0].Related_Student__c = RelatedStudentid; sa[0].Record_Type__c = temp_recordtype;
Hello,
ya. what i understood is, you want to change the value Record_Type__c, when StudentID_SIS__c is XXX(say).
for this:
trigger UpdateStudentAttendance_Before on Student_Attendance__c (before insert)
{
for( Student_Attendance__c objstud: Trigger.new)
{
if(objstud.StudentID_SIS__c = 'XXX')
{
objstud.Record_Type__c = 'YYYY';
}
}
}
this should work for 1st part.
For second part, Im not understanding the certain things,
1) How the two objects are related to each other,
2) which field is related to to which object,
3) what exactly we need to update
-Sunil
I finally was able to write a bulk trigger!!
Thanks!