Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger AutoStudentIDTrigger on Contact (before insert){
- list<Contact> l1 =
- [SELECT Id, Type_of_bursary_contact__c, Student_ID_New__c, Do_Not_Auto_Generate_Student_ID__c FROM Contact WHERE
- Type_of_bursary_contact__c = 'Student' AND RecordTypeId in (SELECT Id FROM RecordType WHERE Name = 'Bursary Contact') AND Student_ID_New__c != NULL
- ORDER BY Student_ID_New__c desc limit 1];
- list<Contact> l2 =
- [SELECT Id, Beneficiary_Number__c,Role_in_group__c FROM Contact WHERE
- RecordTypeId in (SELECT Id FROM RecordType WHERE Name = 'Community Contact') AND Beneficiary_Number__c != NULL
- ORDER BY Beneficiary_Number__c desc limit 1];
- Integer l1size = l1.size();
- Integer l2size = l2.size();
- Decimal NewLatestStudentID = 0.0;
- Decimal NewLatestBeneficiaryID = 0.0;
- If(l1size > 0){
- try {
- NewLatestStudentID = l1[0].Student_ID_New__c;
- }
- Catch (System.NullPointerException e) {
- System.debug('The following exception has occurred: ' + e.getMessage());
- }
- }
- If(l2size > 0){
- NewLatestBeneficiaryID = l2[0].Beneficiary_Number__c;}
- If(trigger.isInsert){
- for(Contact li:Trigger.new) {
- If(li.Type_of_bursary_contact__c == 'Student' & li.Do_Not_Auto_Generate_Student_ID__c == FALSE ){
- li.Student_ID_New__c = NewLatestStudentID+1; }
- If(li.Role_in_group__c != Null & li.Do_Not_Auto_Generate_Beneficiary_Number__c == FALSE ){
- li.Beneficiary_Number__c = NewLatestBeneficiaryID+1; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement