4

I'm getting the error message that is the title of this question. I don't see any documentation for this error and my google searches don't reveal anyone else running into it either. Any guidance?

public class EventFieldUpdates {

public static void updateEvent(List<Event> events) {
    // Get the recordtypeid for planning opportunities
    String recordTypeIdPlanning = ([SELECT id FROM RecordType WHERE Name = 'Planning' LIMIT 1]).get(0).Id;
    String currentYear = String.valueof(System.Today().year());
    Map<Event, Opportunity> eventOppMap = new Map<Event, Opportunity>();
    List<String> eventIds = convertToIdList(events);
    List<Opportunity> opportunities = [SELECT AccountId, StageName FROM Opportunity WHERE Planning_Year__c >= :currentYear AND RecordTypeId = :recordTypeIdPlanning AND AccountId IN :eventIds];
    Opportunity relatedOpp = null;

    // Sort the Opportunities by Event Id
    List<OpportunitySortable> sortableOpps = new List<OpportunitySortable>();
    for(Opportunity opp:opportunities) {
        sortableOpps.add( new OpportunitySortable(opp) );
    }
    sortableOpps.sort();

    // Build Map of events to their correct opportunities. 
    for(Event event:events) {
        // Search for the opportunity related to this event by year and eventid
        relatedOpp = findRelatedOpportunity(event, sortableOpps);
        eventOppMap.put(event, relatedOpp);
    }

    // empty the list of opportunities and re-use it for storing the opportunities that need to be updated 
    opportunities.clear();

    // for each event in the map, get its opportunity and update it if necessary
    for(Event event:eventOppMap.keySet()) {
        Opportunity opp = null;
        if( event.Activity_Type__c == 'Sizing Appointment' ) {
            opp = eventOppMap.get(event);
            // Only update the stagename if the opportunity is in one of these stages
            if( opp.StageName == 'VS-Planning' || opp.StageName == 'VS-Planning Complete' || opp.StageName == 'VS-Contact Complete' ) {
                opp.StageName = 'VS-Fitting Booked';
            }
            opportunities.add(opp);
        }
        else if( event.Activity_Type__c == 'Consultation/Pre-Sale' ) {
            opp = eventOppMap.get(event);
            // Only update the stagename if the opportunity is in one of these stages
            if( opp.StageName == 'VS-Planning' || opp.StageName == 'VS-Planning Complete' || opp.StageName == 'VS-Contact Complete' ) {
                opp.StageName = 'VS-Meeting (Consultation) Booked';
            }
            opportunities.add(opp);
        }
    }
    update(opportunities);



    // Legacy Code that was here prior to 11/15/2013. Must've been written by Chuck Toler - Ethan Willis
    if(event.StartDateTime !=null){
        event.Copy_of_Start__c=event.StartDateTime;
    }
    if(event.EndDateTime !=null){
        event.Copy_of_End__c=event.EndDateTime;
    }
}

/* Helper inner classes and methods */

// Finds the correct opportunity for the given event
public static Opportunity findRelatedOpportunity(Event event, List<OpportunitySortable> opps) {
    // Implement iterative binary search later
    Opportunity opp = null;
    for(OpportunitySortable o : opps) {
        if( o.relatedToEvent(event) ) {
            opp = o.getOpp();
        }
    }
    return opp;
}

public static List<String> convertToIdList(List<SObject> objs) {
    List<String> ids;
    for(SObject so : objs) {
        ids.add( so.Id );
    }
    return ids;
}

public class OpportunitySortable implements Comparable {
    public Opportunity opp;
    public String oppAccount;

    public OpportunitySortable(Opportunity opp2) {
        opp = opp2;
        oppAccount = opp2.AccountId;
    }

    //implement comparable methods.
    public Integer compareTo(Object compareTo) {
        OpportunitySortable compareOpp = (OpportunitySortable)compareTo;
        Integer compareValue = 0;
        String compareOppAccount = compareOpp.AccountId;

        compareValue = oppAccount.compareTo(compareOppAccount);

        return compareValue; 
    }

    // check if this opportunity is the one that belongs to an event
    public Boolean relatedToEvent(Event event) {
        Boolean relatedTo = false;
        String eventId = event.Id;
        String eventYear = String.valueOf(((event.EndDateTime).year()));
        // check if this opportunity has a matching year and accountid to the given event
        if( opp.Planning_Year__c == eventYear && opp.Accountid == eventId ) {
            relatedTo = true;
        }

        return relatedTo;
    }

    public Opportunity getOpp() {
        return opp;
    }
}

}

2

I waited about 30 minutes and kept clicking save, but kept getting this error.

So, I posted this question and went to make a burrito. I just came back, clicked save again and no error!

So the answer is to just wait for salesforce to not be bad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.