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
UtrivUtriv 

Auto Clone / Create the Record

Hi,

I have the following record types for one of my object called "Inspections".

  • Site Visit
  • Inspection
  • Reinspection

Now I have a field called "Results" and the fields appears on all record types mentioned above. If the customer fails inspection then the results field is marked as "Fail". 

Upon faiIing the inspection, I would like to AUTO CREATE a new record and assign a record type as reinspection.

How do I do this?

Thank you in advance!

steve456steve456

You can achieve this by using an after insert,after update trigger......

UtrivUtriv

I am writing the following code...Any one please help for my issue mentioned above..

 

 

Trigger Inspection on Inspection_FSE__c (after insert, after update) {

 

list<Inspection_FSE__c> AddPA = new list<Inspection_FSE__c>();

for( Inspection_FSE__c o : Trigger.new ){
Inspection_FSE__c IN = new Inspection_FSE__c(
Inspection_Type__C = o.Id,
}
insert AddIN


}

steve456steve456

trigger autocreate on Inspection_FSE__c(after insert,after update) {

 

String recordtypeid=[Select Id from RecordType where Name='Reinspection' and SobjectType='Inspection_FSE__c'].Id;

if(Trigger.isInsert){
List< Inspection_FSE__c> off = new List< Inspection_FSE__c>();
for ( Inspection_FSE__c newinsp: Trigger.New){
if(newinsp.Result__c=='Fail'){
off.add (new  Inspection_FSE__c(
Name = newinsp.Name,
Address__c = newinsp.Address__c,
City__c = newinsp.City__c,

RecordTypeid=newinsp.recordypeid,
State__c = newinsp.State__c

));
}
}
insert off;
}

}

UtrivUtriv

Thank you Steve! but somehow it's not working..Let me tell you what exactly I am trying to accomplish here..

 

I have the following 2 objects

 

  • Inspection
  • Inspection FSE (Look up to Inspection)

 

When I Fail the Inspection in InspectionFSE object, the system should copy the Inspection Type (picklist) and MFD Permit (checkbox) and create a completely new record and it should also copy the Inspection Record ID from the Inspection object. Also assign a record type to RIFSE (Reinspection FSE) to a new record.

 

Thank you very much for your help!

 

 

 

 

UtrivUtriv

Can someone please tell me what is wrong with the following trigger? It shows line breaks error.

 

 

trigger autocreate on Inspection_FSE__c(after insert,after update) {

String recordtypeid=[Select Id from RecordType where Name="RIFSE' and SobjectType='Inspection_FSE__c'].Id;

if(Trigger.isInsert){
List<Inspection_FSE__c> off=new List<Inspection_FSE__c>();
for(Inspection_FSE__c newinsp:Trigger.New){
if(newinsp.Result__c=='Fail'){
Inspection_Type__c=newinsp.Inspection_Type__c,
));
}
}
insert off;
}

}

steve456steve456

Inspection_Type__c=newinsp.Inspection_Type__c,

 

Replace this with

 

Inspection_Type__c=newinsp.Inspection_Type__c

UtrivUtriv

nopes..it doesnt help...it still shows linke breaking error..in line 3 

 

String recordtypeid=[Select Id from RecordType where Name="RIFSE' and SobjectType='Inspection_FSE__c'].Id;

steve456steve456

String recordtypeid=[Select Id from RecordType where Name="RIFSE' and SobjectType='Inspection_FSE__c'].Id;

 

 

Replace with

 

String recordtypeid=[Select Id from RecordType where Name='RIFSE' and SobjectType='Inspection_FSE__c'].Id;