0

Object record update via Trigger

HI Team,

 

Could you help me. I am trying to update the object records data by trigger. it throwing setValue() invocation is unsupported for an immutable Record. can you please help me resolving and achieving this requirements?

 

Thanks in advance,

Mithun

4 comments

  • Avatar
    Igor Tsives

    Hello Mithun,

    Could you be updating an old record by chance? Only new record gotten by com.veeva.vault.sdk.api.data.RecordChange#getNew can be updated. 

    Thanks,

    Igor Tsives

  • Avatar
    Mithun Soni

    Hi Igor,

     

    Thanks for your help.

    I have one use case where when i create one object record and add document in that record, metadata details from document should be updated in object record field. when we create first record, then its updating the details, but when we are changing the document from object record, we want based on updated document record, metadata of the object record should get updated. i am getting error while updating the record. could you share a small code which demonstrate both update and insert?

     

    Thanks,

    Mithun

     

  • Avatar
    Igor Tsives

    Hi Mithun,

    Could you please post your source so we can take a look? 

    Thank you,

    Igor

     

  • Avatar
    Mithun Soni

    HI Igor,

     

    Below is my code:

    @RecordTriggerInfo(object = "audit__c", events = {RecordEvent.AFTER_UPDATE})
    public class Audit implements RecordTrigger {

    public void execute(RecordTriggerContext recordTriggerContext) {


    for (RecordChange inputRecord : recordTriggerContext.getRecordChanges()) {


    // Default Expected Date a week ahead
    inputRecord.getOld().setValue("expected_date__c", LocalDate.now().plusWeeks(1));
    //inputRecord.getNew().setValue("expected_date__c", LocalDate.now().plusWeeks(1));
    }
    }
    }

     

    Here in Every update of the object, it should update the field as mentioned in the code.

    I also need the same usecase when We create the record.

    but above code throwing below error:

     

    errorType[OPERATION_NOT_ALLOWED] errorMessage[Vault Java SDK Error: [setValue() invocation is unsupported for an immutable Record] Error Id: [a69b08a6-a44e-448e-92ea-6c8a44758cb7]]

     

     

    Thanks,

    Mithun

Please sign in to leave a comment.