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
hogehogehogehoge 

Hep me! what is this error

I have created the following code, but I am getting an error.
Where should i fix?

For example
・Unexpected token 'OR'.
・Expecting ';' but was: 'AND'
・Field is not writeable: Result__c.ManagedServiceDeptFlg__c
global without sharing class ResultFulfillingAggregateScheduler implements Schedulable{
    
    
    public void execute( SchedulableContext sc ){

        String conditonRecordTypeA = 'OrderEstimated';
        String conditonRecordTypeB = 'OrderRegistration';
        Map<String,Schema.RecordTypeInfo> recordTypeMap = new Map<String,Schema.RecordTypeInfo>();
        for( Schema.RecordTypeInfo info : Result__c.SObjectType.getDescribe().getRecordTypeInfos() ){
            if( info.getDeveloperName() == conditonRecordTypeA || info.getDeveloperName() == conditonRecordTypeB ){
                recordTypeMap.put( info.getDeveloperName() , info );
            }
        }

        List<String> conditionOrderProbabilityRank = new List<String>{ 'A' , 'B' , 'C' };

        Date day = Date.today();
        Date startDate = Date.newInstance( day.year() - ( day.month() < 4 ? 1 : 0 ) , ( day.month() >= 4 || day.month() <= 9 ) ? 4 : 10 , 1 );
        Date endDate = startDate.addMonth( 6 ).addDay( - 1 );

        List<Result__c> resultList = [
            SELECT OrderProbabilityRank__c , RecordTypeId , DXSolutionDeptFlg__c , PlatformSolutionDeptFlg__c , DSPSSolutionDeptFlg__c , ManagedServiceDeptFlg__c , EastJapanSolutionDeptFlg__c , ChubuSolutionDeptFlg__c , WestJapanSolutionDeptFlg__c ,  LimitProfit__c , LimitIncomePartTarget__c
            FROM Result__c
            WHERE ( DXSolutionDeptFlg__c = TRUE OR PlatformSolutionDeptFlg__c = TRUE OR DSPSSolutionDept__c = TRUE OR ManagedServiceDeptFlg__c OR EastJapanSolutionDeptFlg__c OR ChubuSolutionDeptFlg__c OR WestJapanSolutionDeptFlg__c )
              AND ( FulfillingAggregateFlg__c = FALSE )
              AND ( AcceptanceExpectedDate__c >= :startDate AND AcceptanceExpectedDate__c <= :endDate )
              AND ( ( RecordType.DeveloperName = :conditonRecordTypeA AND OrderProbabilityRank__c IN :conditionOrderProbabilityRank ) OR RecordType.DeveloperName = :conditonRecordTypeB )
        ];
        // 集計を保存するレコードを準備する(key = 作成条件テーブルナンバー)
        Map<String,Result__c> resultMap = new Map<String,Result__c>();
        resultMap.put( '01' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'A' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = true  , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '02' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'B' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = true  , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '03' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'C' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = true  , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '04' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'A' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = true  , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '05' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'B' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = true  , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '06' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'C' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = true  , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '07' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'A' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = true  , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '08' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'B' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = true  , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '09' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'C' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = true  , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '10' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'A' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDepFlgt__c = false , ManagedServiceDeptFlg__c = true ,  EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '11' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'B' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = true ,  EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '12' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'C' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = true ,  EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '13' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'A' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDepFlgt__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = true ,  ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '14' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'B' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = true ,  ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '15' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'C' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = true ,  ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '16' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'A' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = true ,  WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '17' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'B' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = true ,  WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '18' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'C' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = true ,  WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '19' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'A' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = true , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );        
        resultMap.put( '20' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'B' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = true , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );        
        resultMap.put( '21' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() , OrderProbabilityRank__c = 'C' , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = true , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );        
        resultMap.put( '22' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = true  , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '23' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = true  , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '24' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = true  , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '25' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = true ,  EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '26' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = true ,  ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '27' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = true ,  WestJapanSolutionDeptFlg__c = false , LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );
        resultMap.put( '28' , new Result__c( RecordTypeId = recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() , FulfillingAggregateFlg__c = true , DXSolutionDeptFlg__c = false , PlatformSolutionDeptFlg__c = false , DSPSSolutionDeptFlg__c = false , ManagedServiceDeptFlg__c = false , EastJapanSolutionDeptFlg__c = false , ChubuSolutionDeptFlg__c = false , WestJapanSolutionDeptFlg__c = true ,  LimitIncomeAchievementSum__c = 0 , LimitIncomeTargetSum__c = 0 ) );        

        for( Result__c result : resultList ){

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'A' && result.DXSolutionDeptFlg__c ){
                resultMap.get( '01' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '01' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'B' && result.DXSolutionDeptFlg__c ){
                resultMap.get( '02' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '02' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'C' && result.DXSolutionDeptFlg__c ){
                resultMap.get( '03' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '03' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'A' && result.PlatformSolutionDeptFlg__c ){
                resultMap.get( '04' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '04' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'B' && result.PlatformSolutionDeptFlg__c ){
                resultMap.get( '05' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '05' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'C' && result.PlatformSolutionDeptFlg__c ){
                resultMap.get( '06' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '06' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'A' && result.DSPSSolutionDeptFlg__c ){
                resultMap.get( '07' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '07' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }
  
            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'B' && result.DSPSSolutionDeptFlg__c ){
                resultMap.get( '08' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '08' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'C' && result.DSPSSolutionDeptFlg__c ){
                resultMap.get( '09' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '09' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'A' && result.ManagedServiceDeptFlg__c ){
                resultMap.get( '10' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '10' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'B' && result.ManagedServiceDeptFlg__c ){
                resultMap.get( '11' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '11' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'C' && result.ManagedServiceDeptFlg__c ){
                resultMap.get( '12' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '12' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'A' && result.EastJapanSolutionDeptFlg__c ){
                resultMap.get( '13' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '13' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'B' && result.EastJapanSolutionDeptFlg__c ){
                resultMap.get( '14' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '14' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            
       
            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'C' && result.EastJapanSolutionDeptFlg__c ){
                resultMap.get( '15' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '15' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'A' && result.ChubuSolutionDeptFlg__c ){
                resultMap.get( '16' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '16' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'B' && result.ChubuSolutionDeptFlg__c ){
                resultMap.get( '17' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '17' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'C' && result.ChubuSolutionDeptFlg__c ){
                resultMap.get( '18' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '18' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }
            // 作成条件テーブル No.19
            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'A' && result.WestJapanSolutionDeptFlg__c ){
                resultMap.get( '19' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '19' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'B' && result.WestJapanSolutionDeptFlg__c ){
                resultMap.get( '20' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '20' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeA ).getRecordTypeId() && result.OrderProbabilityRank__c == 'C' && result.WestJapanSolutionDeptFlg__c ){
                resultMap.get( '21' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '21' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            
 
            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() && result.DXSolutionDeptFlg__c ){
                resultMap.get( '22' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '22' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }
            // 作成条件テーブル No.23
            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() && result.PlatformSolutionDeptFlg__c ){
                resultMap.get( '23' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '23' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() && result.DSPSSolutionDeptFlg__c ){
                resultMap.get( '24' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '24' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() && result.ManagedServiceDeptFlg__c ){
                resultMap.get( '25' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '25' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }            

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() && result.EastJapanSolutionDeptFlg__c ){
                resultMap.get( '26' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '26' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() && result.ChubuSolutionDeptFlg__c ){
                resultMap.get( '27' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '27' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }

            if( result.RecordTypeId == recordTypeMap.get( conditonRecordTypeB ).getRecordTypeId() && result.WestJapanSolutionDeptFlg__c ){
                resultMap.get( '28' ).LimitIncomeAchievementSum__c += LimitProfit__c;
                resultMap.get( '28' ).LimitIncomeTargetSum__c += LimitIncomePartTarget__c;
            }
        }

        insert resultMap.values();
    }

}

 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

The main error in the code is in the query below.
 
SELECT OrderProbabilityRank__c , RecordTypeId , DXSolutionDeptFlg__c , PlatformSolutionDeptFlg__c , DSPSSolutionDeptFlg__c , ManagedServiceDeptFlg__c , EastJapanSolutionDeptFlg__c , ChubuSolutionDeptFlg__c , WestJapanSolutionDeptFlg__c ,  LimitProfit__c , LimitIncomePartTarget__c
            FROM Result__c
            WHERE ( DXSolutionDeptFlg__c = TRUE OR PlatformSolutionDeptFlg__c = TRUE OR DSPSSolutionDept__c = TRUE OR ManagedServiceDeptFlg__c OR EastJapanSolutionDeptFlg__c OR ChubuSolutionDeptFlg__c OR WestJapanSolutionDeptFlg__c )
              AND ( FulfillingAggregateFlg__c = FALSE )
              AND ( AcceptanceExpectedDate__c >= :startDate AND AcceptanceExpectedDate__c <= :endDate )
              AND ( ( RecordType.DeveloperName = :conditonRecordTypeA AND OrderProbabilityRank__c IN :conditionOrderProbabilityRank ) OR RecordType.DeveloperName = :conditonRecordTypeB )
        ];

I hope ManagedServiceDeptFlg__c,EastJapanSolutionDeptFlg__c,ChubuSolutionDeptFlg__c,WestJapanSolutionDeptFlg__c are  checkbox fields. As they were in where condition you should check them with true or false as you did for other checkbox fields like ManagedServiceDeptFlg__c=True and EastJapanSolutionDeptFlg__c=True ..etc


The other error is check if ManagedServiceDeptFlg__c field is formule field as the error is showing that Field is not writeable: Result__c.ManagedServiceDeptFlg__c.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
hogehogehogehoge
Thank you!!
1 .
I hope ManagedServiceDeptFlg__c,EastJapanSolutionDeptFlg__c,ChubuSolutionDeptFlg__c,WestJapanSolutionDeptFlg__c are  checkbox fields. As they were in where condition you should check them with true or false as you did for other checkbox fields like ManagedServiceDeptFlg__c=True and EastJapanSolutionDeptFlg__c=True ..etc →OK!!!

2.
The other error is check if ManagedServiceDeptFlg__c field is formule field as the error is showing that Field is not writeable: Result__c.ManagedServiceDeptFlg__c.
→What does that mean. ManagedServiceDeptFlg__c is a formula (checkbox). I'm sorry Thank you.
Sai PraveenSai Praveen (Salesforce Developers) 
hi,

Does the answer helped you or do you need any other explanation  on it.


Thanks,
hogehogehogehoge
I need an explanation. Please.
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

As said earlier while comparing the checkbox field you should specify TRUE or False in SOQL query where as in formula you can just use the field name ManagedServiceDeptFlg__c which means True. But this does not work in SOQL query.

Second one you cannot edit or modify or create the formula field. This field will be updated automatically  when the record is created or edited. As you are trying to assign the value for this field ManagedServiceDeptFlg__c in resultMap because of which you are getting error. You have to remove that field from putting the value to the map.

Let me know if you need any further explanation .

 If the solution helps, Please mark it as best answer.

Thanks,