I am having an issue updating the Permit record after the project record(child) is created.
When a Permit record is created I need to also create a Project record. I then need to fetch the id from the newly create Project record and update the field permitIds.project__c that resides on the permit record. I am getting an error "Variable does not exist: Id" at:
per.Permit_Project__c = permitProjectsToCreate.Id;
List<Project__c> permitProjectsToCreate = new List<Project__c>();
Project_Template__c permitTemplate;
public void initialize( String sObjectName ){
List<Id> permitIds = new List<Id>();
if( Trigger.isAfter && this.permitTemplate == null ){
List<Project_Template__c> templates = [
SELECT Id FROM Project_Template__c WHERE Name =: 'Permit Project' LIMIT 1
];
if( !templates.isEmpty() ){
this.permitTemplate = templates[ 0 ];
}
}
}
public void bulkBefore(){
if( Trigger.isInsert){
List<Id> permIds = new List<Id>();
for( SObject record : Trigger.new ){
Permit__c newperm = ( Permit__c ) record;
permIds.add( newperm.Id );
}
}
}
public void afterInsert( SObject so ){
Permit__c newPermit = ( Permit__c ) so;
if( permitTemplate != null ){
permitProjectsToCreate.add( new Project__c(
Permit__c = so.Id,
ProjectTemplate__c = permitTemplate.Id
));
}
}
public void andFinally(){
if( Trigger.isInsert && !this.permitProjectsToCreate.isEmpty() ){
insert this.permitProjectsToCreate;
}
For(Permit__c per :permIds){
per.Permit_Project__c = permitProjectsToCreate.Id;
}
}