ChatGPT with Salesforce Apex
ChatGPT is a buzzword today. I tried ChatGPT to see how it works with Salesforce Apex Development. Normally you would go to google for searching the internet. But this one is different. This is not searching the internet for information. Rather it tries from technical documentation and self learns everything.
I am giving below the chat feed which I found it a new way of doing things and it is very promising.
Me:
Hey ChatGPT, Please write a salesforce apex trigger to update the contact name to 'abc'.
ChatGPT:
Here is an Apex trigger that updates the Contact name to 'abc' when a new Contact is created:
This trigger will fire after an update to a Contact record, and it will loop through each updated Contact record in the trigger context variable Trigger.new. For each Contact, it sets the Name field to 'abc'.
Note that this trigger will only work for Contact records that are being updated. If you want to update the name for new Contact records that are being inserted, you will need to use a different trigger event (such as before insert).
Me: Could you please make it to after trigger
领英推荐
ChatGPT: Certainly! Here is the same Apex trigger, modified to fire after an update to a Contact record:
This trigger will fire after an update to a Contact record, and it will loop through each updated Contact record in the trigger context variable Trigger.new. For each Contact, it sets the Name field to 'abc'.
Note that this trigger will only work for Contact records that are being updated. If you want to update the name for new Contact records that are being inserted, you will need to use a different trigger event (such as before insert).
Me: Hey! That is cheeky! Not right. Please add it to the collection and update
ChatGPT: Certainly! Here is an updated Apex trigger that updates the Contact name to 'abc' when a Contact is updated, and stores the updated Contact records in a collection before updating them:
This trigger will fire after an update to a Contact record, and it will loop through each updated Contact record in the trigger context variable Trigger.new. For each Contact, it sets the Name field to 'abc' and adds the updated Contact to a collection. After the loop has completed, the collection of updated Contact records is updated in the database.
Note that this trigger will only work for Contact records that are being updated. If you want to update the name for new Contact records that are being inserted, you will need to use a different trigger event (such as before insert).
Conclusion:
It is not a 100% automation. Certainly it requires a knowledge of how to code Salesforce triggers. But at the same time, people like me have poor memory though we learn, pass exams and forget everything. And some times you do not do certain things every day. And you do Apex one day and Node js or python other day, you completely forget the syntax of Apex that day. That is why good developers do not do well in the technical interviews, lol. And this chatGPT, helps me to activate my memory and develop solutions so quickly. This is not all about coding, and it can help in many areas, such as science, technology, art and what NOT?