You need to sign in to do that
Don't have an account?
Venkata Shiva Koushik Rachapudi
Help with Bulkifying Apex Code
Trigger
trigger SDS_AE_onAccount on Account (before update) {
//load salesmapping table in memory
List<Sales_mapping__c> Shiva = [Select OwnerId, mapping_type__c,AE__c from sales_mapping__c];
List<Account> UpdateSDSAE = new List<Account>();
for(account a: Trigger.new)
{
if(a.Owner_profile__c == 'SDS' || a.Owner_profile__c == 'SDS Manager')
{
a.SDS__c = a.OwnerId;
UpdateSDSAE.add(a);
}
else if(a.Owner_Profile__c=='AE' && trigger.Oldmap.get(a.Id).SDS__c == trigger.Newmap.get(a.Id).SDS__c)
{
a.AE__c = a.OwnerId;
UpdateSDSAE.add(a);
SDSAD.SSDSD(UpdateSDSAE);
//look up the salesmapping table in memory
}
else if(a.AE__c != null && trigger.oldmap.get(a.id).AE__c != trigger.newmap.get(a.id).AE__c){
SDSAD.SSDSD(UpdateSDSAE);
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Class and Method :
public class SDSAD {
public static void SSDSD(List<Account>UpdateSDSAE){
list<account> shiva = [Select Id, AE__c from Account where Id In: UpdateSDSAE];
list<sales_mapping__c> Koushik = [Select Id, AE__c, mapping_type__c,SDS__c from Sales_mapping__c];
for(account a : shiva){
for(sales_mapping__c s: koushik) {
if (a.AE__c == s.AE__c && s.mapping_type__c == 'AE/SDS'){
a.SDS__c = s.SDS__c;
}
else if(a.AE__c == s.AE__c && s.mapping_type__c == 'AE/IWAE'){
a.iWayAE__c = s.sds__c;
}
}
}
}
}
The trigger calls the class based on condition, but i need to bulkify the class without changing the functionality.
Note : Account and Sales_Mapping__c Objects are not related in any way, the sales mapping Object has all mapped AE and SDS users, hence i need to get SDS value from Sales_mapping__c object when AE is the account owner.
trigger SDS_AE_onAccount on Account (before update) {
//load salesmapping table in memory
List<Sales_mapping__c> Shiva = [Select OwnerId, mapping_type__c,AE__c from sales_mapping__c];
List<Account> UpdateSDSAE = new List<Account>();
for(account a: Trigger.new)
{
if(a.Owner_profile__c == 'SDS' || a.Owner_profile__c == 'SDS Manager')
{
a.SDS__c = a.OwnerId;
UpdateSDSAE.add(a);
}
else if(a.Owner_Profile__c=='AE' && trigger.Oldmap.get(a.Id).SDS__c == trigger.Newmap.get(a.Id).SDS__c)
{
a.AE__c = a.OwnerId;
UpdateSDSAE.add(a);
SDSAD.SSDSD(UpdateSDSAE);
//look up the salesmapping table in memory
}
else if(a.AE__c != null && trigger.oldmap.get(a.id).AE__c != trigger.newmap.get(a.id).AE__c){
SDSAD.SSDSD(UpdateSDSAE);
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Class and Method :
public class SDSAD {
public static void SSDSD(List<Account>UpdateSDSAE){
list<account> shiva = [Select Id, AE__c from Account where Id In: UpdateSDSAE];
list<sales_mapping__c> Koushik = [Select Id, AE__c, mapping_type__c,SDS__c from Sales_mapping__c];
for(account a : shiva){
for(sales_mapping__c s: koushik) {
if (a.AE__c == s.AE__c && s.mapping_type__c == 'AE/SDS'){
a.SDS__c = s.SDS__c;
}
else if(a.AE__c == s.AE__c && s.mapping_type__c == 'AE/IWAE'){
a.iWayAE__c = s.sds__c;
}
}
}
}
}
The trigger calls the class based on condition, but i need to bulkify the class without changing the functionality.
Note : Account and Sales_Mapping__c Objects are not related in any way, the sales mapping Object has all mapped AE and SDS users, hence i need to get SDS value from Sales_mapping__c object when AE is the account owner.
Apex class like below
Let us know if this will help you