• Madhuri Kanthekar
  • NEWBIE
  • 15 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
I am able to get Login time from Login History object but not the Logged Out time.
Let me know if anyone have done this before OR can suggest a work around to get Logged out time.
 
Throwing error at line 12, when inserting (data loader) more than 100 records and Trigger works fine for less than 100 records
Please help, below is my trigger - 

trigger AccountTrigger on Account (before insert,before update){
    
    Set<String> groupIdSet = new Set<String>();
    for(Account acc : Trigger.New){
        groupIdSet.add(acc.Pro_Alpha_ID__c);
        system.debug('--Trigger size in for loop1-->'+Trigger.new.size());
        system.debug(groupIdSet);
    }
    
    Map<String,Account> parentAccMap = new Map<String,Account>();   
    List<Account> accList = new List<Account>();
    accList = [SELECT id,Pro_Alpha_ID__c FROM Account WHERE Pro_Alpha_ID__c IN: groupIdSet AND RecordtypeId =: Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId()];
    for(Account acc : accList){
        parentAccMap.put(acc.Pro_Alpha_ID__c,acc);
        system.debug(parentAccMap);
    } 
    
    Map<String,List<Account>> accMap = new Map<String,List<Account>>(); 
    if(Trigger.isBefore){
        system.debug('--Trigger size in for loop3-->'+Trigger.new.size());
        
        for(Account acc : Trigger.New){
            if(acc.Pro_Alpha_ID__c != null && acc.ParentId == null && acc.RecordtypeId != Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId()){
                if(parentAccMap.keySet().contains(acc.Pro_Alpha_ID__c)){
                    acc.ParentId = parentAccMap.get(acc.Pro_Alpha_ID__c).Id;
                } else {
                    if(accMap.keySet().contains(acc.Pro_Alpha_ID__c)){
                        accMap.get(acc.Pro_Alpha_ID__c).add(acc);
                    system.debug(accMap);

                    } else {
                        List<Account> accLst = new List<Account>();
                        accLst.add(acc);
                        system.debug(accLst);
                        accMap.put(acc.Pro_Alpha_ID__c,accLst); 
                        system.debug(accMap);
                    }
                 }
            }
         }
        List<Account> accountsToCreate = new List<Account>();
        
        for(String s : accMap.keySet()){
                                  
            Account accnt = new Account(RecordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId(),
                                        Pro_Alpha_ID__c = s,
                                        Name = accMap.get(s).get(0).Name,
                                        BillingStreet = accMap.get(s).get(0).BillingStreet,
                                        BillingCity = accMap.get(s).get(0).BillingCity,
                                        BillingState = accMap.get(s).get(0).BillingState,
                                        BillingCountry = accMap.get(s).get(0).BillingCountry,
                                        BillingPostalCode = accMap.get(s).get(0).BillingPostalCode
                                        );
                
                insert accnt;
                system.debug(accnt);
            
            for(Account acc : accMap.get(s)){
               system.debug(accMap.get(s)); 
               acc.ParentId = accnt.Id;
             }
            }
        }
}
Below is my code, I want to create Parent Account and Child Account from same group id field i.e.(Pro_Alpha_ID__c - external Id).
Here If Parent account of the perticular group id does not exists then it should create Parent Account with that group id and then its child account.....Currently only child account is created

Please help to solve this


trigger AccountAfterInsertUpdate on Account (after insert) 
{
    Account parentAccObj;  
    List<Account> insertAccMapping = new List<Account>();
    List<Account> updateAccMapping = new List<Account>();
    try{ 
    if(CommonUtility.check){
      CommonUtility.check = false;
       ParentAccObj = [SELECT Id,Name,Pro_Alpha_ID__c FROM Account WHERE RecordTypeId='0129E0000004Ozp' AND Pro_Alpha_ID__c =:trigger.new[0].Pro_Alpha_ID__c];
       Account myAccount=trigger.new[0];
       Account updacc=[select id,Pro_Alpha_ID__c,ParentId from account where id = :myAccount.id];
       system.debug('---------------updacc----->'+updacc);
       system.debug('---------------parentAccObj.Id----->'+parentAccObj.Id);
       updacc.ParentId = parentAccObj.Id;            
       updacc.Pro_Alpha_ID__c = parentAccObj.Pro_Alpha_ID__c;
       update updacc;
      // system.debug('---------------accObj.Pro_Alpha_ID__c----->'+accObj.Pro_Alpha_ID__c);
 //     updateAccMapping.add(updacc);            
   
    }
   }      
    
    catch(Exception e)
    {     
        if(CommonUtility.check){
         CommonUtility.check = false; 
         //create child account first   
         Account childAccount = new Account();         
         childAccount.Name = trigger.new[0].Name;
         childAccount.Phone = trigger.new[0].Phone;
         childAccount.Allgemeine_EMail_Adresse__c = trigger.new[0].Allgemeine_EMail_Adresse__c;
         childAccount.ParentId = trigger.new[0].Id;   
         childAccount.Pro_Alpha_ID__c = trigger.new[0].Pro_Alpha_ID__c;
            system.debug('-------------Exception---------'+e.getMessage());
         //upsert childAccount;  
            
        //create a parent reference
        
        Account parentReference = new Account(Pro_Alpha_ID__c = trigger.new[0].Pro_Alpha_ID__c);
        childAccount.ParentId = parentReference.Id;
            system.debug('----------------childAccount.ParentId--------------'+parentReference.ParentId);
        
       // create parent account now
         Account parentAccount = new Account();         
         parentAccount.Name = trigger.new[0].Name;
         parentAccount.Phone = trigger.new[0].Phone;
         parentAccount.Allgemeine_EMail_Adresse__c = trigger.new[0].Allgemeine_EMail_Adresse__c;
         parentAccount.RecordTypeId = '0129E0000004Ozp';
         parentAccount.Pro_Alpha_ID__c = trigger.new[0].Pro_Alpha_ID__c;
            system.debug('-------------Exception---------'+e.getMessage());
         //upsert parentAccount;  
            
        Database.SaveResult[] results = Database.insert(new SObject[] { parentAccount, childAccount});
        // Check results.
        for (Integer i = 0; i < results.size(); i++) {
        if (results[i].isSuccess()) {
        System.debug('Successfully Created ID: '+ results[i].getId());
        } else {
        System.debug('Error: could not create sobject '+ 'for array element ' + i + '.');
        System.debug(' The error reported was: '+ results[i].getErrors()[0].getMessage() + '\n');
        }
        }
      
    }   
    }     

}
Hi,

I want to write a trigger for my below requirement, how can achieve this?

Use Case - 
We had an customer that works in a big organization. The want to integrate 8 different companies.
 
So every company had there own account data. So for example that we can have 8 different accounts for the same company.
Every account had the same group id. They will be sparated by there mandant.
 
We need a deployment that adds all accounts to one parent account. When we gets new accounts the trigger will check if there is a parent account. When there is no parent account
The system had to create this. And all other accounts with the same group number will be added to this parent account.
 
Parent accounts gets all a separate record Type. We import every da in the night one times accounts.

Please help !
How can I show alert message on my user's home page when workflow rule is triggered ?
How can I show alert message on my user's home page when workflow rule is triggered ?
Throwing error at line 12, when inserting (data loader) more than 100 records and Trigger works fine for less than 100 records
Please help, below is my trigger - 

trigger AccountTrigger on Account (before insert,before update){
    
    Set<String> groupIdSet = new Set<String>();
    for(Account acc : Trigger.New){
        groupIdSet.add(acc.Pro_Alpha_ID__c);
        system.debug('--Trigger size in for loop1-->'+Trigger.new.size());
        system.debug(groupIdSet);
    }
    
    Map<String,Account> parentAccMap = new Map<String,Account>();   
    List<Account> accList = new List<Account>();
    accList = [SELECT id,Pro_Alpha_ID__c FROM Account WHERE Pro_Alpha_ID__c IN: groupIdSet AND RecordtypeId =: Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId()];
    for(Account acc : accList){
        parentAccMap.put(acc.Pro_Alpha_ID__c,acc);
        system.debug(parentAccMap);
    } 
    
    Map<String,List<Account>> accMap = new Map<String,List<Account>>(); 
    if(Trigger.isBefore){
        system.debug('--Trigger size in for loop3-->'+Trigger.new.size());
        
        for(Account acc : Trigger.New){
            if(acc.Pro_Alpha_ID__c != null && acc.ParentId == null && acc.RecordtypeId != Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId()){
                if(parentAccMap.keySet().contains(acc.Pro_Alpha_ID__c)){
                    acc.ParentId = parentAccMap.get(acc.Pro_Alpha_ID__c).Id;
                } else {
                    if(accMap.keySet().contains(acc.Pro_Alpha_ID__c)){
                        accMap.get(acc.Pro_Alpha_ID__c).add(acc);
                    system.debug(accMap);

                    } else {
                        List<Account> accLst = new List<Account>();
                        accLst.add(acc);
                        system.debug(accLst);
                        accMap.put(acc.Pro_Alpha_ID__c,accLst); 
                        system.debug(accMap);
                    }
                 }
            }
         }
        List<Account> accountsToCreate = new List<Account>();
        
        for(String s : accMap.keySet()){
                                  
            Account accnt = new Account(RecordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId(),
                                        Pro_Alpha_ID__c = s,
                                        Name = accMap.get(s).get(0).Name,
                                        BillingStreet = accMap.get(s).get(0).BillingStreet,
                                        BillingCity = accMap.get(s).get(0).BillingCity,
                                        BillingState = accMap.get(s).get(0).BillingState,
                                        BillingCountry = accMap.get(s).get(0).BillingCountry,
                                        BillingPostalCode = accMap.get(s).get(0).BillingPostalCode
                                        );
                
                insert accnt;
                system.debug(accnt);
            
            for(Account acc : accMap.get(s)){
               system.debug(accMap.get(s)); 
               acc.ParentId = accnt.Id;
             }
            }
        }
}
Hi,

I want to write a trigger for my below requirement, how can achieve this?

Use Case - 
We had an customer that works in a big organization. The want to integrate 8 different companies.
 
So every company had there own account data. So for example that we can have 8 different accounts for the same company.
Every account had the same group id. They will be sparated by there mandant.
 
We need a deployment that adds all accounts to one parent account. When we gets new accounts the trigger will check if there is a parent account. When there is no parent account
The system had to create this. And all other accounts with the same group number will be added to this parent account.
 
Parent accounts gets all a separate record Type. We import every da in the night one times accounts.

Please help !