You need to sign in to do that
Don't have an account?

Variable does not exist: ID - Contact Object
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;
}
}
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;
}
}
public static list<contact> attributiontoupsert(List<String> contact){
At the line in question, it uses the List<String> data type instead of the standard object.
I would suggest two changes:
1. Change the parameter name of the method to Contacts
public static list<contact> attributiontoupsert(List<String> contacts){
And change the places reference the parameter accoridngly.
2.Use Schema.SObjectField f = Contact.Fields.ID;
All Answers
Hello Christina,
Can you try changing the statement to
Does that make any difference?public static list<contact> attributiontoupsert(List<String> contact){
At the line in question, it uses the List<String> data type instead of the standard object.
I would suggest two changes:
1. Change the parameter name of the method to Contacts
public static list<contact> attributiontoupsert(List<String> contacts){
And change the places reference the parameter accoridngly.
2.Use Schema.SObjectField f = Contact.Fields.ID;