Skip to main content
Dylan Hone (Hansonwade) ha fatto una domanda in #Apex

Hi Everyone,

I've written the below code but when the 'campainsToUpdate' list (Line 43) has more than one record in it I get this error:

System.DmlException: Update failed. First exception on row 0 with id 70120000000dolQAAQ; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

If I limit the list to one record it will work and update the record any ideas what I'm doing wrong?

Public Class campaignIterationCounter{

Public Static Void iterationCounter(list<campaign> campaignsToUpdate){

string prevEventSeries;

integer i = 0;

List<Campaign> updateCampaigns = new list<campaign>();

for(campaign c: campaignsToUpdate){

if(prevEventSeries == c.Event_Series__c){

system.debug('Prev Event Series = to campaign event series');

i = i++;

c.How_Many_Times_Has_Event_Run__c = i;

updateCampaigns.add(c);

}

Else if(string.isblank(PrevEventSeries) || PrevEventSeries != C.Event_Series__c){

system.debug('Prev ES not = to Campaign ES');

i = 1;

c.How_Many_Times_Has_Event_Run__c = i;

prevEventSeries = c.Event_Series__c;

updateCampaigns.add(c);

}

}

system.debug(UpdateCampaigns);

update updateCampaigns;

}

Public Static Void listDefinition(list<campaign> newCampaigns){

system.debug(newCampaigns);

map<String, campaign> uniqueEventSeries = new map<string, campaign>();

for(campaign c: newCampaigns){

if(!uniqueEventSeries.containsKey(c.event_series__c)) {

uniqueEventSeries.put(c.event_series__c, c);

}

}

list<campaign> campaignsToUpdate = [SELECT ID, Event_Series__c from Campaign where Event_Series__C in :uniqueEventSeries.keyset() Order by Event_Series__c, CreatedDate ASC];

system.debug(campaignsToUpdate);

System.debug('Passing List to Iteration Counter');

iterationCounter(CampaignsToUpdate);

}

}

4 risposte
  1. 26 lug 2021, 09:40

    Ah figured out the issue!

    I was on a partial sandbox using real data and one of the lookup fields linked to a record that didn't exist on the org, everything seems to be working now, thanks both :)

0/9000