Error :- Invalid Data. Review all error messages below to correct your data.

Apex trigger UpdatePaymentDetails caused an unexpected exception, contact your administrator: UpdatePaymentDetails: execution of AfterUpdate caused by: System.StringException: Invalid id: Foundation:

Payment_Details__c is a child object of Payment_Plan__c in Payment_Details__c, Foundation_Amount_Due is to be updated based on change in Payment_Milestone__c picklist field to 'Foundation' in Payment_Plan__c

trigger UpdatePaymentDetails on Payment_Plan__c (after update) {
    Set <Id> PPIds = new Set <Id>();
    For (Payment_Plan__c P : Trigger.New){ 
        If ( P.Payment_Milestone__c != Null ){

    Map<ID,Payment_Details__c> ExistPayDetMap = New Map<ID,Payment_Details__c>(
       [Select ID,Payment_Plan__c ,Payment_Plan__r.Payment_Milestone__c,
       Payment_Plan__r.Unit_Name__r.Base_Apartment_Cost__c, Booking_Amount_Due__c ,
       Foundation_Amount_Due__c from Payment_Details__c WHERE ID IN : PPids]);

    for(Payment_Plan__c p : Trigger.New){
        Payment_Details__c PD =  ExistPayDetMap.get(p.id);
        If ((p.Payment_Milestone__c == 'Foundation') && (PD.Foundation_Amount_Due__c == Null))
            PD.Foundation_Amount_Due__c = 0.10 * PD.Payment_Plan__r.Unit_Name__r.Base_Apartment_Cost__c;

        Update ExistPayDetMap.values();

2 Answers 2


according to your Code, it seems that Payment_Milestone__c is referencing field and you are comparing p.Payment_Milestone__c == 'Foundation'. so this is the error to compare a referencing field with String that is invalid Id.


p.Payment_Milestone__c is an ID (reference) field according to the error, not a picklist field like it says in the question. When you use the == operator on operands of two different types, the compiler will implicitly convert the right operand to the type of the left operand. In your case, the compiled expression behaves like p.Payment_Milestone__c == (ID)'Foundation'. Because strings can be implicitly converted to IDs, this is not a compilation error - however, during execution the ID conversion will check that the string being converted is a valid 15 or 18 character ID, which "Foundation" is not, which throws the error.

Most likely, either Payment_Milestone__c is not the correct field, or you need to reference one of the fields on the object it references, e.g. p.Payment_Milestone__r.Name.

If Payment_Milestone__c is actually a picklist field, then PPIds.add(p.Payment_Milestone__c) will throw the same error if the value of p.Payment_Milestone__c is "Foundation." In this case, you probably meant PPIds.add(p.ID).

  • Got it to reference by Name ie changed from Payment_Details__c PD = ExistPayDetMap.get(p.id) to PD = ExistPayDetMap.get(p.name). Also made the following change ie removed the If condition just to check // If ((p.Payment_Milestone__c == 'Foundation') && (PD.Foundation_Amount_Due__c == Null)) The error still persists Nov 27, 2016 at 2:08
  • @RajivV.Subramanian OK, try putting a try-catch block around your code and use the catch block to write the line number to the debug log, then update your code to indicate which line threw the exception. That said, I actually think that your line PPIds.add(p.Payment_Milestone__c) may be where the problem is - if Payment_Milestone__c is a picklist field and its value is Foundation, it will throw the same error. Did you mean PPIds.add(p.ID)? Nov 27, 2016 at 3:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .