0

I need to check that a picklist field = "Active" and that it's previous value did not equal "Active" (only need to fire when this one field has changed). I am attempting to do this with the following line:

if (P.Project_Status__c == 'Active' && P.Opportunity__c != Null && oldProjectMap.get(P.Project_Status__c) != 'Active')

But am receiving the error: "Comparison arguments must be compatible types: Project__c, String"

What am I doing wrong?

Below is my entire class

public class ProjectUtil {
    public static void UpdateOppStage (List<Project__c> Projects, map<id,Project__c> oldProjectMap) {
        Set<Id> ActiveProjectOpps = new Set<Id>();
        Set<Id> CompleteProjectOpps = new Set<Id>();
        //update
        if (oldProjectMap != null){
            for (Project__c P : Projects) {
            if (P.Project_Status__c == 'Active' && P.Opportunity__c != Null && oldProjectMap.get(P.Project_Status__c) != 'Active'){
                ActiveProjectOpps.add(P.Opportunity__c);
            }
            else if (P.Project_Status__c == 'Complete' && P.Opportunity__c != Null){
                CompleteProjectOpps.add(P.Opportunity__c);
            }   
        }
        }
        // insert 
        else if (oldProjectMap == null){
            for (Project__c P : Projects) {
            if (P.Project_Status__c == 'Active' && P.Opportunity__c != Null){
                ActiveProjectOpps.add(P.Opportunity__c);
            }
            else if (P.Project_Status__c == 'Complete' && P.Opportunity__c != Null){
                CompleteProjectOpps.add(P.Opportunity__c);
            }   
        }
        }

        List <Opportunity> ActiveOppsToUpdate = [SELECT id, StageName FROM Opportunity WHERE id in:ActiveProjectOpps];
        List <Opportunity> CompleteOppsToUpdate = [SELECT id, StageName FROM Opportunity WHERE id in:CompleteProjectOpps];

        for (Opportunity item: ActiveOppsToUpdate){
            item.StageName = 'Delivery';
        }
        for (Opportunity item: CompleteOppsToUpdate){
            item.StageName = 'Post Delivery Internal Meeting';
        }

        update ActiveOppsToUpdate;
        update CompleteOppsToUpdate;
        }
 }
  • Get(p.id).Project_Status__c ... – sfdcfox Mar 12 '15 at 1:18
1

The result from calling get is the value type of the map (Project__c). This means you still need to reference a field to compare to. Also, since the key type of map is ID, you also need to get the record by its ID.

if (P.Project_Status__c == 'Active' && P.Opportunity__c != Null && oldProjectMap.get(P.id).Project_Status__c != 'Active')

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.