2

Have 2 managed packages.

  1. One package contains Recurring object.
  2. Another package contains Receipt object.
  3. Opportunity has lookup fields to Recurring object and to Receipt.
  4. Created text field 'Donations List' on Recurring to see list of all receipts for this recurring.
  5. Created trigger on Opportunity after update trigger checks if Opportunity lookup to Recurring is not empty execute SOQL to get all receipt names from receipts.

    SELECT Id, Name, Receipt__c, Receipt__r.Name FROM Opportunity WHERE Recurring__c=:recurringID

The problem is - when Receipt creates it populates receipt__c field on opportunity and saves the opportunity. On Saving Opportunity trigger fires to get receipt number populate into recurring object, but SOQL does not return correct receipt number. SOQL returns Receipt ID for Receipt__c field and returns [Name Set by Trigger] for Receipt__r.Name.

Is there a way to get correct receipt number in this situation?

It seems like when receipt creates it has a trigger on insert/update that updates Opportunity lookup field Receipt__c. At the same time on Opportunity (using another trigger) I'am getting Receipt number of receipt that invoked opportunity changing.

Thanks,

5
  • 1
    What's the difference between receipt number and Receipt__r.Name (if there is one)? Also, are you literally getting a value of "[Name Set by Trigger]", or is it returning a name value from the wrong field or wrong record?
    – Mobot818
    Commented Nov 27, 2018 at 17:45
  • What are the managed packages? You may need to reach out to the vendor of the Receipt package to get clarity on exactly when the Name field is populated with its ultimate value, since it sounds like they may have some complex and possibly asynchronous code working there.
    – David Reed
    Commented Nov 27, 2018 at 17:48
  • @Mobot818 receipt number and receipt__r.Name are the same. Field Name contains a number of receipt something like 'RT000012' Yes SOQL literally returns [Name Set by Trigger] instead of actual Name I am expecting.
    – Mike
    Commented Nov 27, 2018 at 17:58
  • Can you insert Receipt__c and see if it fires any Future/Quueable calls in Apex Jobs section? Commented Nov 27, 2018 at 18:09
  • @Pranay Jaiswal It doesnt fire future calls. It is just invoking one trigger from another.
    – Mike
    Commented Nov 27, 2018 at 18:16

1 Answer 1

1

From the detail provided, it looks like the Name field for Receipt__c when created has initial value as " [Name Set by Trigger]". I believe there is some queuable, Future call going in the background which updates the Name with the actual value you see. 'RT000012' in your case

Whatever may be the case, the Name field is updated. I believe you can write a Trigger on Receipt__c after update. It will have the name present. Once you get the name you can query the related opportunity. From related opportunity, you can get Recurring records and then update the Donation list on it.

You must log in to answer this question.

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