function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mario01Mario01 

Urgent!! How to change trigger to Apex class??? I have a urgent requirement

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..

Jeff MayJeff May

You can create an Apex class that has a static method.  That method would accept a List<Distressed_Area_Association__c>.

 

public with sharing myClass {

  public static void doWork(List<Distressed_Area_Association__c>) {

    // put your trigger code here
  }
}

 Then you can call myClass.doWork() and pass it the List<Distressed_Area_Association__c> you want to manipulate.