• Christina Tomaselli
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 7
    Replies
I have a trigger that I am using to update related accounts (based on a custom field not a lookup) so I am using SOQL but when i try and execute I am getting a self-reference error:

trigger UpdateBusinessAgreement on Account (before update) {
    for (Account a : Trigger.new){
        String TIN = a.Tax_ID_Number__c;
        String AID = a.Id;
        List<Account> matchingAccounts = [SELECT ID, Business_Agreement_Completed__c, Tax_ID_Number__c FROM Account WHERE ID <>: AID AND Tax_ID_Number__c =: TIN];
        if (a.Business_Agreement_Completed__c == 'Received - Complete'){
            for (Account Acc : matchingAccounts){
                    Acc.Business_Agreement_Completed__c = 'Received - Complete';
                    update acc;
            }
        }
    }
}
I am trying to write a trigger to update all the accounts with a shared field (Tax ID number) whenever any of the accounts changes. This is what I have, but am getting an error message Unexpected Token 'TIN'. 

trigger UpdateBusinessAgreement on Account (before update) {
    for (Account a : Trigger.new){
        String TIN = a.Tax_ID_Number__c;
        List<Account> matchingAccounts = [SELECT ID, Business_Agreement_Completed__c, Tax_ID_Number__c FROM Account WHERE Tax_ID_Number__c = TIN];
        if (a.Business_Agreement_Completed__c == 'Received - Complete'){
            for (Account Acc : matchingAccounts){
                Acc.Business_Agreement_Completed__c = 'Received - Complete';
                    }
        }
    }
}
I wrote an apex class to update a series of fields with the results from the SOQL query in the class. The fields I am updating are on the contact object and I am trying to match using contact ID, but am getting an error that variable ID does not exist. Any suggestions? Here is my code:
public class AttributionRollup {
    @InvocableVariable (required=true)
    public List<SObject> distinctprovider;
 
    @InvocableMethod(label='Attribution Rollup' description='upserts attribution totals into Contact records.' category='Contract Practice Junction')
    public static list<contact> attributiontoupsert(List<String> contact){
        //populate the distinctprovider list with the most recent attribution records 
               List<SObject> distinctprovider = [SELECT Contact__c, Health_Plan_Contract__c, Run_As_Of_Date__c, Max(Attributed_Lives__c)  
                                                 FROM Contract_Practice_Junction__c 
                                                 WHERE Contact__c IN:contact 
                                                 GROUP BY Run_As_Of_Date__c, Contact__c, Health_Plan_Contract__c
                                                 ORDER BY Run_As_Of_Date__c DESC
                                                 LIMIT 1];
        AggregateResult[] groupedResults = distinctprovider;

         List<Contact> ContactPlanList = new List<Contact> ();
         for (AggregateResult ar : groupedResults)  {
        
            Contact c = new Contact();
            
             Switch on String.valueOf(ar.get('Health_Plan_Contract__c')){
                 
                 when 'aetna comm ID'{
                     c.Aetna_Commercial__c =(Double)ar.get('expr0');
                     System.debug('Aetna_Commercial__c' + ar.get('expr0'));
                 }
                 
                 when 'Affinity Medicaid ID'{
                     c.Affinity_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('Affinity_Medicaid__c' + ar.get('expr0'));
                 }
                 
                 when 'Emblem comm ID'{
                     c.Emblem_Commercial__c =(Double)ar.get('expr0');
                     System.debug('Emblem_Commercial__c' + ar.get('expr0'));
                 }
                 
                 when 'Emblem Medicaid ID'{
                     c.Emblem_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('Emblem_Medicaid__c' + ar.get('expr0'));
                 }
                                  
                 when 'Empire comm ID'{
                     c.Empire_Commercial__c =(Double)ar.get('expr0');
                     System.debug('Empire_Commercial__c' + ar.get('expr0'));
                 }
                                  
                 when 'Fidelis Medicaid ID'{
                     c.Fidelis_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('Fidelis_Medicaid__c' + ar.get('expr0'));
                 }
                                  
                 when 'Healthfirst Medicaid ID'{
                     c.HEALTHFIRST_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('HEALTHFIRST_Medicaid__c' + ar.get('expr0'));
                 }
                 
                 when 'Healthfirst Medicare ID'{
                     c.HEALTHFIRST_Medicare__c =(Double)ar.get('expr0');
                     System.debug('HEALTHFIRST_Medicare__c' + ar.get('expr0'));
                 }
                 
                 when 'OSCAR Medicare ID'{
                     c.OSCAR_Medicare__c =(Double)ar.get('expr0');
                     System.debug('OSCAR_Medicare__c' + ar.get('expr0'));
                 }
                 
                 when 'Wellcare Medicare ID'{
                     c.Wellcare_Medicare__c =(Double)ar.get('expr0');
                     System.debug('Wellcare_Medicare__c' + ar.get('expr0'));
                 }
                 
             }
                        
            //c.Run_Date__c =Date.valueOf(ar.get('Run_As_Of_Date__c'));
            //System.debug('Run_Date__c' + ar.get('Run_As_Of_Date__c'));
            
            ContactPlanList.add(c);
        }        
     
        Schema.SObjectField f = Contact.ID;
        
        Database.UpsertResult[] results = database.upsert(ContactPlanList,f,false);
        
        for (Database.UpsertResult result : results) {
            if (!result.isSuccess()) {
                Database.Error[] errs = result.getErrors();
                for(Database.Error err : errs)
                    System.debug(err.getStatusCode() + ' - ' + err.getMessage());
            }
        }
       System.debug('distinctprovider'+distinctprovider) ;       
        return ContactPlanList;
    }
}
Hi,

I am trying to create a summary record on a related object using a SOQL totals query and an apex trigger. I am running into 2 issues I am having trouble referencing the summed fields from within my totals query and my trigger doesn't seem to be doing the upsert based on the external ID field Rollup_ID__c which matches in both objects. Here is my Trigger: 
trigger MeasureUpsert on Contract_Practice_Junction__c (after insert) 

    //Run totals query to aggregate all Contract_Practice_Junction__c records to get the sum of all numerators and denominators
    for (Contract_Practice_Junction__c measure : [SELECT Rollup_ID__c, rate_type__c, Health_Plan_Contract__c, Measure__c, Run_As_Of_Date__c, 
                                                  sum(Count_in_Denominator__c), sum(Count_in_Numerator__c)
                                                  FROM Contract_Practice_Junction__c GROUP BY Rollup_ID__c, rate_type__c, Health_Plan_Contract__c, Measure__c, Run_As_Of_Date__c])
    //use a for loop to run through all the aggregate records and upsert values to the 
    {
        //for each measure in the for loop, upsert a new Contract_Quality_Performance__c record with the values of the totals query using Rollup_ID__c as the external ID
        Contract_Quality_Performance__c CQP = new Contract_Quality_Performance__c();
            CQP.Rollup_ID__c            = measure.Rollup_ID__c;
            CQP.Rate_Type__c            = measure.rate_type__c;
            CQP.Measure__c              = measure.Measure__c;
            CQP.Health_Plan_Contract__c = measure.Health_Plan_Contract__c;
            CQP.Run_Date__c                = measure.Run_As_Of_Date__c;
            CQP.Denominator__c            = measure.sum(Count_in_Denominator__c);
            CQP.Numerator__c            = measure.sum(Count_in_Numerator__c);
            upsert CQP;
    }
}

Thank you in advance for any help/suggestions. 
I have a trigger that I am using to update related accounts (based on a custom field not a lookup) so I am using SOQL but when i try and execute I am getting a self-reference error:

trigger UpdateBusinessAgreement on Account (before update) {
    for (Account a : Trigger.new){
        String TIN = a.Tax_ID_Number__c;
        String AID = a.Id;
        List<Account> matchingAccounts = [SELECT ID, Business_Agreement_Completed__c, Tax_ID_Number__c FROM Account WHERE ID <>: AID AND Tax_ID_Number__c =: TIN];
        if (a.Business_Agreement_Completed__c == 'Received - Complete'){
            for (Account Acc : matchingAccounts){
                    Acc.Business_Agreement_Completed__c = 'Received - Complete';
                    update acc;
            }
        }
    }
}
I am trying to write a trigger to update all the accounts with a shared field (Tax ID number) whenever any of the accounts changes. This is what I have, but am getting an error message Unexpected Token 'TIN'. 

trigger UpdateBusinessAgreement on Account (before update) {
    for (Account a : Trigger.new){
        String TIN = a.Tax_ID_Number__c;
        List<Account> matchingAccounts = [SELECT ID, Business_Agreement_Completed__c, Tax_ID_Number__c FROM Account WHERE Tax_ID_Number__c = TIN];
        if (a.Business_Agreement_Completed__c == 'Received - Complete'){
            for (Account Acc : matchingAccounts){
                Acc.Business_Agreement_Completed__c = 'Received - Complete';
                    }
        }
    }
}
I wrote an apex class to update a series of fields with the results from the SOQL query in the class. The fields I am updating are on the contact object and I am trying to match using contact ID, but am getting an error that variable ID does not exist. Any suggestions? Here is my code:
public class AttributionRollup {
    @InvocableVariable (required=true)
    public List<SObject> distinctprovider;
 
    @InvocableMethod(label='Attribution Rollup' description='upserts attribution totals into Contact records.' category='Contract Practice Junction')
    public static list<contact> attributiontoupsert(List<String> contact){
        //populate the distinctprovider list with the most recent attribution records 
               List<SObject> distinctprovider = [SELECT Contact__c, Health_Plan_Contract__c, Run_As_Of_Date__c, Max(Attributed_Lives__c)  
                                                 FROM Contract_Practice_Junction__c 
                                                 WHERE Contact__c IN:contact 
                                                 GROUP BY Run_As_Of_Date__c, Contact__c, Health_Plan_Contract__c
                                                 ORDER BY Run_As_Of_Date__c DESC
                                                 LIMIT 1];
        AggregateResult[] groupedResults = distinctprovider;

         List<Contact> ContactPlanList = new List<Contact> ();
         for (AggregateResult ar : groupedResults)  {
        
            Contact c = new Contact();
            
             Switch on String.valueOf(ar.get('Health_Plan_Contract__c')){
                 
                 when 'aetna comm ID'{
                     c.Aetna_Commercial__c =(Double)ar.get('expr0');
                     System.debug('Aetna_Commercial__c' + ar.get('expr0'));
                 }
                 
                 when 'Affinity Medicaid ID'{
                     c.Affinity_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('Affinity_Medicaid__c' + ar.get('expr0'));
                 }
                 
                 when 'Emblem comm ID'{
                     c.Emblem_Commercial__c =(Double)ar.get('expr0');
                     System.debug('Emblem_Commercial__c' + ar.get('expr0'));
                 }
                 
                 when 'Emblem Medicaid ID'{
                     c.Emblem_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('Emblem_Medicaid__c' + ar.get('expr0'));
                 }
                                  
                 when 'Empire comm ID'{
                     c.Empire_Commercial__c =(Double)ar.get('expr0');
                     System.debug('Empire_Commercial__c' + ar.get('expr0'));
                 }
                                  
                 when 'Fidelis Medicaid ID'{
                     c.Fidelis_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('Fidelis_Medicaid__c' + ar.get('expr0'));
                 }
                                  
                 when 'Healthfirst Medicaid ID'{
                     c.HEALTHFIRST_Medicaid__c =(Double)ar.get('expr0');
                     System.debug('HEALTHFIRST_Medicaid__c' + ar.get('expr0'));
                 }
                 
                 when 'Healthfirst Medicare ID'{
                     c.HEALTHFIRST_Medicare__c =(Double)ar.get('expr0');
                     System.debug('HEALTHFIRST_Medicare__c' + ar.get('expr0'));
                 }
                 
                 when 'OSCAR Medicare ID'{
                     c.OSCAR_Medicare__c =(Double)ar.get('expr0');
                     System.debug('OSCAR_Medicare__c' + ar.get('expr0'));
                 }
                 
                 when 'Wellcare Medicare ID'{
                     c.Wellcare_Medicare__c =(Double)ar.get('expr0');
                     System.debug('Wellcare_Medicare__c' + ar.get('expr0'));
                 }
                 
             }
                        
            //c.Run_Date__c =Date.valueOf(ar.get('Run_As_Of_Date__c'));
            //System.debug('Run_Date__c' + ar.get('Run_As_Of_Date__c'));
            
            ContactPlanList.add(c);
        }        
     
        Schema.SObjectField f = Contact.ID;
        
        Database.UpsertResult[] results = database.upsert(ContactPlanList,f,false);
        
        for (Database.UpsertResult result : results) {
            if (!result.isSuccess()) {
                Database.Error[] errs = result.getErrors();
                for(Database.Error err : errs)
                    System.debug(err.getStatusCode() + ' - ' + err.getMessage());
            }
        }
       System.debug('distinctprovider'+distinctprovider) ;       
        return ContactPlanList;
    }
}
Hi,

I am trying to create a summary record on a related object using a SOQL totals query and an apex trigger. I am running into 2 issues I am having trouble referencing the summed fields from within my totals query and my trigger doesn't seem to be doing the upsert based on the external ID field Rollup_ID__c which matches in both objects. Here is my Trigger: 
trigger MeasureUpsert on Contract_Practice_Junction__c (after insert) 

    //Run totals query to aggregate all Contract_Practice_Junction__c records to get the sum of all numerators and denominators
    for (Contract_Practice_Junction__c measure : [SELECT Rollup_ID__c, rate_type__c, Health_Plan_Contract__c, Measure__c, Run_As_Of_Date__c, 
                                                  sum(Count_in_Denominator__c), sum(Count_in_Numerator__c)
                                                  FROM Contract_Practice_Junction__c GROUP BY Rollup_ID__c, rate_type__c, Health_Plan_Contract__c, Measure__c, Run_As_Of_Date__c])
    //use a for loop to run through all the aggregate records and upsert values to the 
    {
        //for each measure in the for loop, upsert a new Contract_Quality_Performance__c record with the values of the totals query using Rollup_ID__c as the external ID
        Contract_Quality_Performance__c CQP = new Contract_Quality_Performance__c();
            CQP.Rollup_ID__c            = measure.Rollup_ID__c;
            CQP.Rate_Type__c            = measure.rate_type__c;
            CQP.Measure__c              = measure.Measure__c;
            CQP.Health_Plan_Contract__c = measure.Health_Plan_Contract__c;
            CQP.Run_Date__c                = measure.Run_As_Of_Date__c;
            CQP.Denominator__c            = measure.sum(Count_in_Denominator__c);
            CQP.Numerator__c            = measure.sum(Count_in_Numerator__c);
            upsert CQP;
    }
}

Thank you in advance for any help/suggestions.