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
Synthia B.Synthia B. 

Multiple Page Layouts

When a new Plan Year is created, custom object Implementation will have 11 records (Implementation Category), which are created by an apex trigger.

User-added image

Each category then has it's own set of records which are also created by an apex trigger. 

User-added image

User-added image

For the Contract/Required Documents category, it's set of tasks should have a different page layout consisting of contract specific details. 

User-added image

I have created Contract/Required Documents page layout and assigned it to the Contract/Required Documentsrecord type however, the layout remain the same for all 11 records (Implementation Categories). 

User-added image

How can I correct this? 

Thanks in Advance. 
 
Best Answer chosen by Synthia B.
Neetu_BansalNeetu_Bansal
Hi Synthia,

You need to check the name of that category, if it is 'Contracts/Required Documents', only then assign record type to it like:
Implementation_Task__c rec = new implementation_task__c( Name = str, Implementation__c = currPlanYear.Id );
if( currPlanYear.Name == 'Contracts/Required Documents' )
{
rec.RecordTypeId = contractRecordTypeId;
}
Let me know, if you need any other help.

Thanks,
Neetu

All Answers

Synthia B.Synthia B.
trigger IMPAI on Plan_Year__c (after insert)
{
List <Implementation__c> impToInsert = new List <Implementation__c>();
Map<Integer, String> impMap = new Map<Integer, String>();
impMap.put(1, 'Pre-Implementation');
impMap.put(2, 'Vendor Selection');
impMap.put(3, 'Plan Design Confirmation');
impMap.put(4, 'Rate Confirmation');
impMap.put(5, 'Planning/Implementation');
impMap.put(6, 'Account Structure/Billing');
impMap.put(7, 'Contracts/Required Documents');
impMap.put(8, 'Communications- (TO BE CONFIRMED)');
impMap.put(9, 'Data Requirements');
impMap.put(10, 'Open Enrollment');
impMap.put(11, 'Post Enrollment');


for (Plan_Year__c currPlanYear : Trigger.New)
{
//Remember to change the integer value when updating the records
   for(Integer i=1; i<=11; i++)
   {
       Implementation__c rec = new implementation__c (Name = impMap.get(i), Plan_Year_1__c = currPlanYear.Id); 
       ImpToInsert.add(rec);
   }
}

Database.saveResult[] sr = database.insert(impToInsert,false);  

 for(integer x=0;x<sr.size();x++)
 {
    if(sr[x].isSuccess() == false)
      system.debug(logginglevel.error,sr[x].getErrors()[0].getMessage());
 }    
}
Synthia B.Synthia B.
Trigger ImplementationTasks on Implementation__c (after insert)
{
    List <Implementation_Task__c> impToInsert = new List <Implementation_Task__c>();

    Map<String, List<String>> impMap = new Map<String, List<String>>();

impMap.put('Contracts/Required Documents', new List<String>{'Broker of Record Letter (BOR)', 'Business Associate Agreements (BAA)', 'Non-Disclosure Agreements (NDA)', 'Clearview Master Agreement', 'Letter of Intent - Quantum', 'Vendor Service Agreements', 'Medical', 'PBM', 'Quantum - Care Coordination', 'Medical Bill Review', 'HCBB - Pricing Transparency', 'Wellness', 'Dental', 'Vision', 'Life & Disability', 'Supplemental', 'Summary of Benefit Coverage (SBCs)', 'Summary Plan Descriptions (SPDs / Certificate Booklets)'});

for( Implementation__c currPlanYear: trigger.new )
    {
        if( impMap.containsKey( currPlanYear.Name ))
        {
            for( String str : impMap.get( currPlanYear.Name ))
            {
                Implementation_Task__c rec = new implementation_task__c( Name = str, Implementation__c = currPlanYear.Id );
                ImpToInsert.add(rec);
            }

        }
    }

    if( ImpToInsert.size() > 0 )
        insert impToInsert;
}
ClintLeeClintLee
Hi Synthia,

It doesn't look like you're assigning the "Contracts/Required Documents" record type to your Implementation Tasks.
 
Id contractRecordTypeId = [select Id from RecordType where SObjectType = 'Implementation_Task__c' and Name = 'Contracts/Required Documents' limit 1].Id;

// assign the Record Type when creating your Task.
Implementation_Task__c rec = new Implementation_Task__c(Name = str, Implementation__c = currPlanYear.Id, RecordTypeId = contractRecordTypeId);

Hope that helps,

Clint
Synthia B.Synthia B.
Hi Bill, 

I am getting the following error when I create a new plan year. 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger IMPAI caused an unexpected exception, contact your administrator: IMPAI: System.LimitException: Too many SOQL queries: 101


The trigger has more records but I only included the contracts record. 
Trigger ImplementationTasks on Implementation__c (after insert)
{
    List <Implementation_Task__c> impToInsert = new List <Implementation_Task__c>();

    Map<String, List<String>> impMap = new Map<String, List<String>>();

impMap.put('Contracts/Required Documents', new List<String>{'Broker of Record Letter (BOR)', 'Business Associate Agreements (BAA)', 'Non-Disclosure Agreements (NDA)', 'Clearview Master Agreement', 'Letter of Intent - Quantum', 'Vendor Service Agreements', 'Medical', 'PBM', 'Quantum - Care Coordination', 'Medical Bill Review', 'HCBB - Pricing Transparency', 'Wellness', 'Dental', 'Vision', 'Life & Disability', 'Supplemental', 'Summary of Benefit Coverage (SBCs)', 'Summary Plan Descriptions (SPDs / Certificate Booklets)'});

for( Implementation__c currPlanYear: trigger.new )
    {
        if( impMap.containsKey( currPlanYear.Name ))
        {
            for( String str : impMap.get( currPlanYear.Name ))
            {
            Id contractRecordTypeId = [select Id from RecordType where SObjectType = 'Implementation_Task__c' and Name = 'Contracts/Required Documents' limit 1].Id;
            // assign the Record Type when creating your Task.
                Implementation_Task__c rec = new implementation_task__c( Name = str, Implementation__c = currPlanYear.Id );
                ImpToInsert.add(rec);
            }

        }
    }

    if( ImpToInsert.size() > 0 )
        insert impToInsert;
}

 
ClintLeeClintLee
Move the Record Type query above the for-loop.  You only need to query it once.

Example:
Id contractRecordTypeId = [select Id from RecordType where SObjectType = 'Implementation_Task__c' and Name = 'Contracts/Required Documents' limit 1].Id;

for(Implementation__c currPlanYear : trigger.new )

 
Synthia B.Synthia B.
Hi Bill, 

I moved it but the page layout remains the same as the others. Am I missing something else? 
ClintLeeClintLee
In the latest code snippet you posted it doesn't look like you're assigning the RecordTypeId to the record.

Like this:
Implementation_Task__c rec = new implementation_task__c( Name = str, Implementation__c = currPlanYear.Id, RecordTypeId = contractRecordTypeId );

 
Synthia B.Synthia B.
Thank for your help Bill.

I am not sure what I am doing wrong but now the contract page layout is set for all the record types. I am not sure where to locate the record Id's since these records are being inserted by an apex trigger. I am still very new to apex triggers. 


 
Trigger ImplementationTasks on Implementation__c (after insert)
{
    List <Implementation_Task__c> impToInsert = new List <Implementation_Task__c>();

    Map<String, List<String>> impMap = new Map<String, List<String>>();

    impMap.put('Contracts/Required Documents', new List<String>{'Broker of Record Letter (BOR)', 'Business Associate Agreements (BAA)', 'Non-Disclosure Agreements (NDA)', 'Clearview Master Agreement', 'Letter of Intent - Quantum', 'Vendor Service Agreements', 'Medical', 'PBM', 'Quantum - Care Coordination', 'Medical Bill Review', 'HCBB - Pricing Transparency', 'Wellness', 'Dental', 'Vision', 'Life & Disability', 'Supplemental', 'Summary of Benefit Coverage (SBCs)', 'Summary Plan Descriptions (SPDs / Certificate Booklets)'});
    
    Id contractRecordTypeId = [select Id from RecordType where SObjectType = 'Implementation_Task__c' and Name = 'Contracts/Required Documents' limit 1].Id;
            // assign the Record Type when creating your Task.
    for( Implementation__c currPlanYear: trigger.new )
    {
        if( impMap.containsKey( currPlanYear.Name ))
        {
            for( String str : impMap.get( currPlanYear.Name ))
            {
                Implementation_Task__c rec = new implementation_task__c( Name = str, Implementation__c = currPlanYear.Id, RecordTypeId = contractRecordTypeId );
                ImpToInsert.add(rec);

            }

        }
    }

    if( ImpToInsert.size() > 0 )
        insert impToInsert;
}

 
Neetu_BansalNeetu_Bansal
Hi Synthia,

You need to check the name of that category, if it is 'Contracts/Required Documents', only then assign record type to it like:
Implementation_Task__c rec = new implementation_task__c( Name = str, Implementation__c = currPlanYear.Id );
if( currPlanYear.Name == 'Contracts/Required Documents' )
{
rec.RecordTypeId = contractRecordTypeId;
}
Let me know, if you need any other help.

Thanks,
Neetu
This was selected as the best answer
Synthia B.Synthia B.
Thank you Neetu. All resolved :-)