• Zishan Razzaq
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi,
Some of my code that has been working for about 2 years now is recieveing a Visualy Force Error - The URL goes to a recession page which I have never seen before.
Someone else has this issue... /visualforce/recsession?? Please advise on how to correct.
Thanks
Z
Hi all,
I am trying to write a trigger that would obtain unique set of values from a child object and update the parent object Multi-Select Picklist field.
Now the issue is that when I edit the same record in the child twice and the status is equal to Active it comes up in the Multi-Select twice when it should be there once.
For example,
Market Type Child field = RV,Truck,Car
On the account the Market Type is the same until I edit the child record again let say RV
on the Account it will then show RV;RV;Truck;Car...
Here is my code:
trigger PopulateMarketType on Account_Market__c (after insert,after update) {
/*************************Variable Section*************************************/
    List<ID> AccIDs = new List<ID>();
    
    List<Account> updateAccList = new List<Account>();
    
    Map<ID,Account> AccUpdateMap = new Map<ID,Account>();
    
    Set<String> subAccNames = new Set<String>();
    
    List<Account> clearvaluesMT = new List<Account>();
    
    String[] UniqueMTs;
    
    String FinalUnique;
    Integer x=0;
 /****************************************************************************/
 
/**********************Retrieve Account Id's from the new AMI records***************/    
    For( Account_Market__c ami: Trigger.New)
    {
            AccIDs.add(ami.Account__c);
    }
     
    For(Account acc : [Select ID, Market_Type__c from Account where ID in:AccIDs])
    {
             AccUpdateMap.put(acc.ID ,acc );
    }

    
    /****I like to clear out all the values in the Market Type Field in the Account and then re-insert them in****/
   /*For (Account clearthis : [Select Market_Type__c from Account where ID in:AccIDs])
    {
            System.Debug('zzz32'+clearthis.Market_Type__c);
            clearthis.Market_Type__c = '';   
                    
            clearvaluesMT.add(clearthis);
            System.Debug('zzz35'+clearthis.Market_Type__c);
             update clearvaluesMT;  
    }    
    If (clearvaluesMT != null && clearvaluesMT.size() > 0) 
    {             
        update clearvaluesMT;   
        System.Debug('zzz38'+clearvaluesMT);
    }*/
 /**********************************************************************************************************/   
    /**Re-Insert the Market Types in for the associated Account*****/ 
    For (Account_Market__c amii: Trigger.New)
    {
    
             Account updateacc = AccUpdateMap.get(amii.Account__c);
                If (amii.Status__c == 'Active') 
                 {
                     
                     If (updateacc.Market_Type__c ==null)
                     {                        
                         updateacc.Market_Type__c = amii.Market_Type__c;   
                      }
                      else
                      {
                      
                      //1st - get all the values
                          updateacc.Market_Type__c += +';'+ amii.Market_Type__c; 
                           
                     //2nd - place them in a set to  become unique     
                          subAccNames.add(updateacc.Market_Type__c );
                     
                     //3rd - put them in a string   
                          FinalUnique = String.valueof(subAccNames);
                          System.Debug('zzz74'+FinalUnique);
                      
                      //4th - take away the {} from value
                            if(FinalUnique.contains('{'))
                            {
                                FinalUnique = FinalUnique.replace('{', ' ');
                            }
                            
                            if(FinalUnique.contains('}'))
                            {
                                FinalUnique = FinalUnique.replace('}', ' ');                                  
                            }                         
                     
                     //5th - Finally update the Market type with the Final Value     
                         updateacc.Market_Type__c  = FinalUnique;      
                 
                     }               
                 updateAccList.add(updateacc);    
                 } 
                   
    }
    If (updateAccList != null && updateAccList.size() > 0)
        
            update updateAccList;

}

Thank you
Hi all,
I am trying to write a trigger that would obtain unique set of values from a child object and update the parent object Multi-Select Picklist field.
Now the issue is that when I edit the same record in the child twice and the status is equal to Active it comes up in the Multi-Select twice when it should be there once.
For example,
Market Type Child field = RV,Truck,Car
On the account the Market Type is the same until I edit the child record again let say RV
on the Account it will then show RV;RV;Truck;Car...
Here is my code:
trigger PopulateMarketType on Account_Market__c (after insert,after update) {
/*************************Variable Section*************************************/
    List<ID> AccIDs = new List<ID>();
    
    List<Account> updateAccList = new List<Account>();
    
    Map<ID,Account> AccUpdateMap = new Map<ID,Account>();
    
    Set<String> subAccNames = new Set<String>();
    
    List<Account> clearvaluesMT = new List<Account>();
    
    String[] UniqueMTs;
    
    String FinalUnique;
    Integer x=0;
 /****************************************************************************/
 
/**********************Retrieve Account Id's from the new AMI records***************/    
    For( Account_Market__c ami: Trigger.New)
    {
            AccIDs.add(ami.Account__c);
    }
     
    For(Account acc : [Select ID, Market_Type__c from Account where ID in:AccIDs])
    {
             AccUpdateMap.put(acc.ID ,acc );
    }

    
    /****I like to clear out all the values in the Market Type Field in the Account and then re-insert them in****/
   /*For (Account clearthis : [Select Market_Type__c from Account where ID in:AccIDs])
    {
            System.Debug('zzz32'+clearthis.Market_Type__c);
            clearthis.Market_Type__c = '';   
                    
            clearvaluesMT.add(clearthis);
            System.Debug('zzz35'+clearthis.Market_Type__c);
             update clearvaluesMT;  
    }    
    If (clearvaluesMT != null && clearvaluesMT.size() > 0) 
    {             
        update clearvaluesMT;   
        System.Debug('zzz38'+clearvaluesMT);
    }*/
 /**********************************************************************************************************/   
    /**Re-Insert the Market Types in for the associated Account*****/ 
    For (Account_Market__c amii: Trigger.New)
    {
    
             Account updateacc = AccUpdateMap.get(amii.Account__c);
                If (amii.Status__c == 'Active') 
                 {
                     
                     If (updateacc.Market_Type__c ==null)
                     {                        
                         updateacc.Market_Type__c = amii.Market_Type__c;   
                      }
                      else
                      {
                      
                      //1st - get all the values
                          updateacc.Market_Type__c += +';'+ amii.Market_Type__c; 
                           
                     //2nd - place them in a set to  become unique     
                          subAccNames.add(updateacc.Market_Type__c );
                     
                     //3rd - put them in a string   
                          FinalUnique = String.valueof(subAccNames);
                          System.Debug('zzz74'+FinalUnique);
                      
                      //4th - take away the {} from value
                            if(FinalUnique.contains('{'))
                            {
                                FinalUnique = FinalUnique.replace('{', ' ');
                            }
                            
                            if(FinalUnique.contains('}'))
                            {
                                FinalUnique = FinalUnique.replace('}', ' ');                                  
                            }                         
                     
                     //5th - Finally update the Market type with the Final Value     
                         updateacc.Market_Type__c  = FinalUnique;      
                 
                     }               
                 updateAccList.add(updateacc);    
                 } 
                   
    }
    If (updateAccList != null && updateAccList.size() > 0)
        
            update updateAccList;

}

Thank you