function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arc30Arc30 

Trigger issue to create a offer record

Hi

Kindly help in the following issue

When an Account is inserted/updated with Customer Type as ‘VIP’ and Status as ‘Customer’, create an offer record to provide a free service.(Please use trigger). 
Note: Please follow all coding standards(no naming conventions Eg: Trigger ByPass, Bulk Trigger etc.. )

please let me know the steps

Regards
Archith
Best Answer chosen by Arc30
Vickal Gupta 15Vickal Gupta 15

If the answer helped you. Please marked as best answer.

A little change in last two lines. Actually it should be

if(offerRList.size() >0){
	     insert offerRList;
}

All Answers

Vickal Gupta 15Vickal Gupta 15
I think the below code might help you.
trigger offRecord on Account (after insert, after update) {
   
 List<OfferRecord__c> offerRList = new Lis<OfferRecord__c>();
 
   for(Account a : trigger.new)
   {
      if( a.CustomerType__c == 'VIP' && a.Status__c == 'Customer' ){
       OfferRecord__c oRcd=new OfferRecord__c();
       oRcd.accountid=a.accountid;
       oRcd.lastname=a.name;
       offerRList . add(oRcd);
      }
   }
   if(oRcd.size() >0){
     insert oRcd;
    }
}


Please replace fields name and object name as per your object and field name.
Arc30Arc30
Thank you so much Vickal
Vickal Gupta 15Vickal Gupta 15

If the answer helped you. Please marked as best answer.

A little change in last two lines. Actually it should be

if(offerRList.size() >0){
	     insert offerRList;
}
This was selected as the best answer
Arc30Arc30
done