Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Call my class when record inserted in the staging table

Posted on by 2,985

Hi,

When I modify the name of the customer, the record should get inserted into the staging table. when the record gets inserted into the table my class should run. The responses from the class should get inserted against the same record.

I created a method in the custable to insert the record in the staging table.(record get inserted in the staging table). I called this method in the modified field.

I called the class run method after a super call in the table insert method, but the record not inserted.

Any idea,what's the best approach.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Call my class when record inserted in the staging table

    I'm sorry, but it's not clear to me what should be questions and what are mere statements. It'll help if you end sentences intended as questions with the question mark.

    Let me assume that the three paragraphs mean three questions.

    1) When you run a batch, it'll call run() method, therefore that's where you should place logic you want to run in batch.

    2) Yes, as discusse above.

    3) Yes, I guess, depending on what you actually mean by this question.

  • Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: Call my class when record inserted in the staging table

    Hi Martin,

    Could you please answer the above question about my understanding?

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Call my class when record inserted in the staging table

    That's another benefit of using a batch. You can simply try to process the record on the next run.

  • Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: Call my class when record inserted in the staging table

    Hi Martin,

    For some reason if the record is not processed say network error , in that case do I need to apply retry mechanism or else by default the batch running in the background will take care.

  • Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: Call my class when record inserted in the staging table

    Hi Martin,

    Correct me if I am wrong,

    So I should add my logic in the run method of a class which extends runbasebatch.

    The batch job should run the background, whenever the record gets inserted in the staging table it checks for the status new and my logic in the run method will execute. So after my logic ends I need to change the status column as complete.

    Is it a good practice to create a staging table 

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Call my class when record inserted in the staging table

    I'm not talking about about adding a RunBase class as a query, but using a query inside. Like this:

    public void run()
    {
    	MyStaging myStaging;
    	
    	while select myStaging
    		where myStaging.Status == MyStatus::New
    	{
    		...
    	}
    }

  • Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: Call my class when record inserted in the staging table

    I know how to extend the class in run base    batch , but to add it as a query I am not aware on that process.Its interesting .If you share me any document or any clue I will take it away from that

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Call my class when record inserted in the staging table

    It's pretty easy: your staging table will have a status field. For example, it may be enum with values like New, Processed and Failed. Your batch will use a query to process just records with Status = New, it'll process them and change the Status to either Processed or Failed.

  • Pravasti AK Profile Picture
    Pravasti AK 2,985 on at
    RE: Call my class when record inserted in the staging table

    So what's your approach,

    if any update happen in the cust table it should process and should store the responses back that's where I included the concept I staging table.Client gave the URL and I consumed it.

    As you said the batch will take care of the unprocessed records how to achieve that, can you explain that a bit in detail.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Call my class when record inserted in the staging table

    Point 1: You can make synchronous calls from a batch job in the same way as from any other code. But if your idea is doing  a web service call from update() of CustTable, this idea is wrong, as I explained. You mustn't do it. If a batch doesn't work for you for some reason, please explain the business problem that's preventing this desing. Note that "I want it" isn't a business justification.

    Point 2: I said the batch would be running every minute, therefore you don't need any code in insert(). The batch would use a query to find all unprocessed records and handle them.

    Point 3: I don't know what you mean "bypassing an error" and what prevents you from handling exceptions in the way you want. You'll have to be more specific.

    Point 4: As I explained in one of your previous threads, you can use try/catch block to catch exceptions. It sounds like you have a problem with it, but you forgot to explain it, therefore I can't comment on it unless you do it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans