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
saraazsaraaz 

to create an record when an trigger runs

this is my code i have done to create an case record whenever the booking record is created

But the case record is not created wen i create a booking record 

can anyone help mw out from this???

 

trigger CreatingCase on Bookings__c (after insert , after update) 
{
    set<id> BookingSet = new set<id>();
    for(integer i=0;i<trigger.size;i++)
        {
            BookingSet.add(trigger.new[i].id);
        }    
    list<case> CaseList = new list<case>();
    for(integer i=0;i<trigger.size;i++)
        {
            case caseinstance = new case();
            caseinstance.Vehicles__c = trigger.new[i].Vehicle__c;
            caseinstance.Zone_Value__c = trigger.new[i].Zone__c;
            caseinstance.Booking_No__c = trigger.new[i].name;
            CaseList.add(caseinstance);
        }
     insert CaseList;
}

Best Answer chosen by Admin (Salesforce Developers) 
Grazitti InteractiveGrazitti Interactive

Hi,

Please use following code (:.

 

trigger CreatingCase on Bookings__c (after insert , after update)
{
List<case> CaseList = new List<case>();
for(Bookings__c booking :Trigger.New){
case caseinstance = new case();
caseinstance.Vehicles__c =  booking.Vehicle__c;
caseinstance.Zone_Value__c = booking.Zone__c;
caseinstance.Booking_No__c =  booking.name;
CaseList.add(caseinstance);
}

system.debug(CaseList+'CaseList===');
try{insert CaseList;}catch(Exception e){}
}

 

Thanks

www.grazitti.com

All Answers

Grazitti InteractiveGrazitti Interactive

Hi,

Please use following code (:.

 

trigger CreatingCase on Bookings__c (after insert , after update)
{
List<case> CaseList = new List<case>();
for(Bookings__c booking :Trigger.New){
case caseinstance = new case();
caseinstance.Vehicles__c =  booking.Vehicle__c;
caseinstance.Zone_Value__c = booking.Zone__c;
caseinstance.Booking_No__c =  booking.name;
CaseList.add(caseinstance);
}

system.debug(CaseList+'CaseList===');
try{insert CaseList;}catch(Exception e){}
}

 

Thanks

www.grazitti.com

This was selected as the best answer
saraazsaraaz

Sorry still the case record has not been created wen i create a booking record

Grazitti InteractiveGrazitti Interactive

Hi,

 

I have edited code of previous post, please use it .

Also make sure that -

1. Field level security on case field.

2. Is there any required field on Case which not getting any value in Trigger.

 

If You are still getting any problem , then goto debug log and let me know exception on insertion of caseList.

 

/**If this post helps you then please don't forget to give me kudo's by clicking star aside and mark it as a solution.***/

 

Thanks

Grazitti

souvik9086souvik9086

Check in debug log whether is it causing any error or not and whether it is executing after addition to the list.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks