You need to sign in to do that
Don't have an account?
Naishadh
Message Edited by Naishadh on 11-12-2008 02:31 AM
Batch Update Trigger problem
I have created trigger on my role custom object. If I create, update or delete single record on role it works fine and execute trigger and apex code. But if I try to create/update multiple record using excel connector it simply ignore the trigger.
Please guide.
Message Edited by Naishadh on 11-12-2008 02:31 AM
Sorry i didn't get it . Trigger code are as under.
and apex class code
System.debug(contactRole);
Set<ID> userIds = new Set<ID> ();
//Retrieve userIds
for(Integer i = 0;i < contactRole.size();i++) {
userIds.add(contactRole[i].Contact__c);
}
//fetch contact record based on userIds.
Contact[] con = [ Select c.Primary_Brand_roll_up__c, c.Contacts_roll_up__c, c.Business_Unit_roll_up__c, c.Id From Contact c where c.Id in :userIds];
contactRole = [ Select s.Contact__r.Name, s.Contact__c, s.Primary_Brand__c, s.Business_Unit__c From Roles_Contacts__c s where s.Contact__c in :userIds];
System.debug('No of Record' + con.size());
//clear all content of contact custom field
//not support single quotes only.
con[0].Contacts_roll_up__c = 't';
con[0].Primary_Brand_roll_up__c = 't';
con[0].Business_Unit_roll_up__c = 't';
for(Integer i = 0;i < contactRole.size();i++) {
if(contactRole[i].Contact__r != null && contactRole[i].Contact__r.Name != null) {
if(con[0].Contacts_roll_up__c.length() > 1) {
if(!con[0].Contacts_roll_up__c.contains(contactRole[i].Contact__r.Name)) {
con[0].Contacts_roll_up__c += ',' + contactRole[i].Contact__r.Name;
}
} else {
con[0].Contacts_roll_up__c = contactRole[i].Contact__r.Name;
}
}
if(contactRole[i].Business_Unit__c != null) {
if(con[0].Business_Unit_roll_up__c.length() > 1) {
if(!con[0].Business_Unit_roll_up__c.contains(contactRole[i].Business_Unit__c)) {
con[0].Business_Unit_roll_up__c += ',' + contactRole[i].Business_Unit__c;
}
} else {
con[0].Business_Unit_roll_up__c = contactRole[i].Business_Unit__c;
}
}
if(contactRole[i].Primary_Brand__c != null) {
if(con[0].Primary_Brand_roll_up__c.length() > 1) {
if(!con[0].Primary_Brand_roll_up__c.contains(contactRole[i].Primary_Brand__c)) {
con[0].Primary_Brand_roll_up__c += ',' + contactRole[i].Primary_Brand__c;
}
} else {
con[0].Primary_Brand_roll_up__c = contactRole[i].Primary_Brand__c;
}
}
}
//check for no data.
if(con[0].Contacts_roll_up__c.length() == 1) {
con[0].Contacts_roll_up__c = '';
}
if(con[0].Business_Unit_roll_up__c.length() == 1) {
con[0].Business_Unit_roll_up__c = '';
}
if(con[0].Primary_Brand_roll_up__c.length() == 1) {
con[0].Primary_Brand_roll_up__c = '';
}
try {
update con;
}catch(System.DmlException e){
System.debug('We caught a DML exception: ' + e.getDmlMessage(0));
}
}
}
Message Edited by Naishadh on 11-13-2008 03:29 AM