• Nidhi Sharma 3
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi, 
Scenario is when child object is inserted or updated then Multi-select picklist gets updated with the values. 
Of course it has to be unique hence this is why I am utilizing the Set method.
So for example:
If child object (Account Market) related to Account has 12 records all active, values are A;B;C;D;E;F;G;H;I;J;K;L
the insert to the Market Type multi-picklst field on Account comes up as A;B;C;D;E;F;G;H;I;J...
After the 'J' value why is it inserting '...' ???????
Here is my code, what is incorrect please help...
trigger ConcatenateAcctMarketType on Account_Market__c (after insert, after update) {
// variable declaration....
    Public Set <id> AcctIdSet = new Set<id>(); 
    Public Set <id> AcctParentIdSet = new Set<id>();
    Public List<Account> AcctList = new List<Account>();
    Public List<Account> AcctChildList = new List<Account>();
    Public String []  tempvar ;
    Public String[] tempvartest;
    Set<String> subAccNames = new Set<String>();
    Public String Tempvar2;
    
//DealerGroup Variables....    
    String [] TempVarDG ;
    String Tempvar2DG;   
    Set<String> UniqueMarketTypesDG = new Set<String>();

    For(Account_Market__c AcctMkt : Trigger.New)
    {
    AcctIdSet.add(AcctMkt.Account__c);   
    }
    AcctList = [SELECT id,Market_Type__c, Test_Market_Type__c ,ParentId ,(SELECT Market_Type__c,Status__c, Account__c
                    FROM Account_Markets__r  WHERE Status__c = 'Active') 
                    FROM Account 
                    WHERE ID IN :AcctIdSet];
    system.debug('AcctList '+AcctList);
    
// update dealergroup logic....                    
            For(Account Acts : AcctList )
            {                
                if (Acts.ParentId != NULL )
                {              
                AcctParentIdSet.add(Acts.ParentId);               
                }
            } 
             system.debug('AcctParentIdSet---->>'+AcctParentIdSet);       
// end of creating delaergroup set....  
          
    for (Account acc : AcctList)
    {
system.debug('Account List size-->>'+AcctList.size());        
        for(Account_Market__c mktyp: acc.Account_Markets__r) 
        { 
system.debug('mktyp List size-->>'+acc.Account_Markets__r.size());
        if (acc.id == mktyp.Account__c &&mktyp.Status__c == 'Active')
        { 
            if(mktyp.Market_Type__c != NULL )
            { // to avoid null pointer exception....                 
                system.debug('Market_Type__c--->>'+mktyp.Market_Type__c);
                Tempvar = + mktyp.Market_Type__c.split(';'); 
                
                
                system.debug('Tempvar--->>'+Tempvar);                                              
            }
            //if(subAccNames.size()!= 10){
                subAccNames.addAll(Tempvar );
            //}
        system.debug('subAccNames-->'+subAccNames);
        Tempvar2 = String.valueof(subAccNames);
        system.debug ('Tempvar2 49'+Tempvar2);
            if(Tempvar2 != null)
         {
            if(Tempvar2.contains('{'))
            {
            Tempvar2 = Tempvar2.replace('{', ' ');
            }    
            if(Tempvar2.contains('}'))
            {
            Tempvar2 = Tempvar2.replace('}', ' ');                                  
            }        
            if(Tempvar2.contains(','))
            {
            Tempvar2 = Tempvar2.replace(',', ';');
            }            
            If(Tempvar2==null)
            {
            Tempvar2='';
            }
        }
     }  
     system.debug('Tempvarssss2'+Tempvar2);                   
     }
        acc.Market_Type__c = tempvar2;
        acc.Test_Market_Type__c = String.valueof(subAccNames);
        system.debug('acc.Market_Type__c--->'+acc.Market_Type__c); 
        if (Tempvar != NULL)
        { 
        Tempvar.clear();
        }
        subAccNames.clear(); 
        Tempvar2 = '';          
    }
    system.debug('AcctList '+AcctList); 
    update AcctList ;
Thanks
Nidhi

Hi, 
Scenario is when child object is inserted or updated then Multi-select picklist gets updated with the values. 
Of course it has to be unique hence this is why I am utilizing the Set method.
So for example:
If child object (Account Market) related to Account has 12 records all active, values are A;B;C;D;E;F;G;H;I;J;K;L
the insert to the Market Type multi-picklst field on Account comes up as A;B;C;D;E;F;G;H;I;J...
After the 'J' value why is it inserting '...' ???????
Here is my code, what is incorrect please help...
trigger ConcatenateAcctMarketType on Account_Market__c (after insert, after update) {
// variable declaration....
    Public Set <id> AcctIdSet = new Set<id>(); 
    Public Set <id> AcctParentIdSet = new Set<id>();
    Public List<Account> AcctList = new List<Account>();
    Public List<Account> AcctChildList = new List<Account>();
    Public String []  tempvar ;
    Public String[] tempvartest;
    Set<String> subAccNames = new Set<String>();
    Public String Tempvar2;
    
//DealerGroup Variables....    
    String [] TempVarDG ;
    String Tempvar2DG;   
    Set<String> UniqueMarketTypesDG = new Set<String>();

    For(Account_Market__c AcctMkt : Trigger.New)
    {
    AcctIdSet.add(AcctMkt.Account__c);   
    }
    AcctList = [SELECT id,Market_Type__c, Test_Market_Type__c ,ParentId ,(SELECT Market_Type__c,Status__c, Account__c
                    FROM Account_Markets__r  WHERE Status__c = 'Active') 
                    FROM Account 
                    WHERE ID IN :AcctIdSet];
    system.debug('AcctList '+AcctList);
    
// update dealergroup logic....                    
            For(Account Acts : AcctList )
            {                
                if (Acts.ParentId != NULL )
                {              
                AcctParentIdSet.add(Acts.ParentId);               
                }
            } 
             system.debug('AcctParentIdSet---->>'+AcctParentIdSet);       
// end of creating delaergroup set....  
          
    for (Account acc : AcctList)
    {
system.debug('Account List size-->>'+AcctList.size());        
        for(Account_Market__c mktyp: acc.Account_Markets__r) 
        { 
system.debug('mktyp List size-->>'+acc.Account_Markets__r.size());
        if (acc.id == mktyp.Account__c &&mktyp.Status__c == 'Active')
        { 
            if(mktyp.Market_Type__c != NULL )
            { // to avoid null pointer exception....                 
                system.debug('Market_Type__c--->>'+mktyp.Market_Type__c);
                Tempvar = + mktyp.Market_Type__c.split(';'); 
                
                
                system.debug('Tempvar--->>'+Tempvar);                                              
            }
            //if(subAccNames.size()!= 10){
                subAccNames.addAll(Tempvar );
            //}
        system.debug('subAccNames-->'+subAccNames);
        Tempvar2 = String.valueof(subAccNames);
        system.debug ('Tempvar2 49'+Tempvar2);
            if(Tempvar2 != null)
         {
            if(Tempvar2.contains('{'))
            {
            Tempvar2 = Tempvar2.replace('{', ' ');
            }    
            if(Tempvar2.contains('}'))
            {
            Tempvar2 = Tempvar2.replace('}', ' ');                                  
            }        
            if(Tempvar2.contains(','))
            {
            Tempvar2 = Tempvar2.replace(',', ';');
            }            
            If(Tempvar2==null)
            {
            Tempvar2='';
            }
        }
     }  
     system.debug('Tempvarssss2'+Tempvar2);                   
     }
        acc.Market_Type__c = tempvar2;
        acc.Test_Market_Type__c = String.valueof(subAccNames);
        system.debug('acc.Market_Type__c--->'+acc.Market_Type__c); 
        if (Tempvar != NULL)
        { 
        Tempvar.clear();
        }
        subAccNames.clear(); 
        Tempvar2 = '';          
    }
    system.debug('AcctList '+AcctList); 
    update AcctList ;
Thanks
Nidhi

Hello, I'm trying to finalize a trigger to update. I am receiving an error on foreign key invalid relationships.

 

- Implementation_Site__c is child to Grant__c

- Country__c field is on Implementation_Site__c

- Countries__c is on Grant__c  - this is the field that needs to be populated with infinite number of Country__c values coming from child records. 

 

Current code:

 

//This Trigger will fire after insert, update, delete and undelete
trigger trgConCatCountries on Implementation_Site__c (after insert, after update, after delete, after undelete) {

//If the event is insert or undelete, this list takes New Values or else it takes old values
List<Implementation_Site__c> ProjStrategyList = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;

//to store Project Ids
List<Id> ProjectIds = new List<Id>();

//Loop through the Records to store the project Id values from the Implementation Site
for (Implementation_Site__c proj_Strat : ProjStrategyList) {
ProjectIds.add(proj_Strat.Grant__c);
}

//Sub-query to get the projects and all its Child Records where Id is equal to the Ids stored in ProjectIds
//Implementation_Sites__r is the Child Relationship name appended by '__r' as it is a custom object

List<Grant__c> ProjectList = [
select
id,
(select id,Name, Grant__r.Name, Country__c, District_State__c from Implementation_Sites__r),
Grant__c
from
Grant__c
where
id in :ProjectIds];
//Loop through the List and store the Child Records as a String of values in Long Text Area Field i.e Countries__c

for (Grant__c proj : ProjectList) {

if(proj.Implementation_Sites__r.size() > 0)
{
proj.Countries__c = string.valueOf(proj.Implementation_Sites__r[0].Country__c);

for(integer i=1;i < proj.Implementation_Sites__r.size();i++)
{
proj.Countries__c = proj.Countries__c + '; ' + string.valueOf(proj.Implementation_Sites__r[i].Country__c);
}
}
else
proj.Countries__c = null;

}

//update the List
update ProjectList;


}

 

 

Help! Thanks!

 

  • August 09, 2013
  • Like
  • 1

Hello, I'm trying to finalize a trigger to update. I am receiving an error on foreign key invalid relationships.

 

- Implementation_Site__c is child to Grant__c

- Country__c field is on Implementation_Site__c

- Countries__c is on Grant__c  - this is the field that needs to be populated with infinite number of Country__c values coming from child records. 

 

Current code:

 

//This Trigger will fire after insert, update, delete and undelete
trigger trgConCatCountries on Implementation_Site__c (after insert, after update, after delete, after undelete) {

//If the event is insert or undelete, this list takes New Values or else it takes old values
List<Implementation_Site__c> ProjStrategyList = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;

//to store Project Ids
List<Id> ProjectIds = new List<Id>();

//Loop through the Records to store the project Id values from the Implementation Site
for (Implementation_Site__c proj_Strat : ProjStrategyList) {
ProjectIds.add(proj_Strat.Grant__c);
}

//Sub-query to get the projects and all its Child Records where Id is equal to the Ids stored in ProjectIds
//Implementation_Sites__r is the Child Relationship name appended by '__r' as it is a custom object

List<Grant__c> ProjectList = [
select
id,
(select id,Name, Grant__r.Name, Country__c, District_State__c from Implementation_Sites__r),
Grant__c
from
Grant__c
where
id in :ProjectIds];
//Loop through the List and store the Child Records as a String of values in Long Text Area Field i.e Countries__c

for (Grant__c proj : ProjectList) {

if(proj.Implementation_Sites__r.size() > 0)
{
proj.Countries__c = string.valueOf(proj.Implementation_Sites__r[0].Country__c);

for(integer i=1;i < proj.Implementation_Sites__r.size();i++)
{
proj.Countries__c = proj.Countries__c + '; ' + string.valueOf(proj.Implementation_Sites__r[i].Country__c);
}
}
else
proj.Countries__c = null;

}

//update the List
update ProjectList;


}

 

 

Help! Thanks!

 

  • August 09, 2013
  • Like
  • 1