You need to sign in to do that
Don't have an account?
Utriv
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!
You can achieve this by using an after insert,after update trigger......
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
}
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;
}
}
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
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!
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;
}
}
Inspection_Type__c=newinsp.Inspection_Type__c,
Replace this with
Inspection_Type__c=newinsp.Inspection_Type__c
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;
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;