• Mario01
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I have a Junction object as Distressed_Area_Association__c And Parent as Deal__c and Distressed_Area__c.

 

I have a trigger which Updates parent field (Deal) when  and new record is added to distressed area association. 

We have unique names in Distressed Area. As soon as Distressed Area gets associated with Distressed Area Association it update Value on field of Deal as YES.

 

Here is trigger,

trigger ENT_Trigger_PopulateDistressedAA on Distressed_Area_Association__c (after insert, after update)
{

    set<id> DealIDs = new set<id>();
    set<id> DdataIDs = new set<id>();
    
    for(Distressed_Area_Association__c l : trigger.new)
    {
        DealIDs.add(l.NMTC_Deal__c);
        DdataIDs.add(l.NMTC_Distressed_Area__c);

    }
   
    List<Deal__c> deals= [select id, Name, PovRate2530__c from Deal__c where id in :DealIDs ];
    List<Distressed_Area__c> da = [select id, Name from Distressed_Area__c where id in:DdataIDs ];
    
      
        
  for(Distressed_Area_Association__c l : trigger.new)
        { 
        
           if( da[0].name == 'TIF District / Enterprise Zone Program')
           {
            deals[0].TIFDistEntZoneProgram__c= 'YES';
           
           }

           if(da[0].name == 'Appalachian Regional Commission / Delta Regional Authority')
           {
            deals[0].AppalachianRegComDelta__c= 'YES';
           
           }           
           if(da[0].name == 'Brownfields')
           {
            deals[0].BrownfieldRedevArea__c= 'YES';
           
           }           
                      
        }
    update deals;
     
     
}

 

I tried writing page refence method as I want to update values on Click of Button. I aaded commandButton to my VF page and tried writing method.

 

public PageReference SyncDistressedAreaAssociations()
{
set<id> DealIDs = new set<id>();
List<Deal__c> deal = [SELECT Name, AppalachianRegComDelta__c, TIFDistEntZoneProgram__c, BrownfieldRedevArea__c,Colonias__c, DesiEZECRC__c,ADesHUBZone__c,DesigNativAmerican__c,DesigRedev__c,EncomHOPEVIRedev__c,
HighMigrationRuralCounty__c,LocatedHotZone__c, MedInc60__c, Median6070__c,MedicallyUnderservedArea__c,
Non_MetropolitanCensusTract__c,PovRate2530__c,PovRate30__c,TrgtgAraHighDstres_Othr__c,
UnEmpRate1_251_50__c,UnEmp1_5__c FROM Deal__c where id in:DealIDs];

 

List<Distressed_Area_Association__c > disAreaAso = [SELECT NMTC_Allocatee_Round__c, NMTC_Deal__c, NMTC_Distressed_Area__c FROM Distressed_Area_Association__c ];

 

List<Distressed_Area__c> distressArea = [select id, Name from Distressed_Area__c];

 

Map<String, ID> distressAreaMap = new Map<String, ID>();


for(Distressed_Area__c Darea: distressArea )
{
distressAreaMap.get(Darea.Name);
if( distressArea.name == 'TIF District / Enterprise Zone Program')
}

for(Distressed_Area_Association__c distressAreaA : disAreaAso )
{

 

}

/* for(Distressed_Area_Association__c dealToUpdate: deal )
{
String idToUpdate = distressAreaMap.get(dealToUpdate.Distressed_Area__c);
if(idToUpdate!=null)
{
if(idToUpdate.length()>15)
{
idToUpdate = idToUpdate.left(15);
}
containerToUpdate.Entity_Id__c = idToUpdate;
}

} */
return null;

}

 

 

Please help I am nwe to apex coding..

I have a question, Why do we need to disable Triggers at the time of Data migtation? And if we have to do this then what abt Data which never gets updated. 

I am not sure how to overcome this situation. Other way round is to update field already in csv file. But that cannot be handle for large number of records.

If anyone faced the same problem please provide your solution.

Thanks.