Main Class:

@RestResource(urlMapping='/updateFaturamento/*')
global  class contractFat { 

    public class ContractJSON {

        public List<Contract> Contract;

        public class Contract {
            public String idSalesForce;
            public String dtEmissao;
            public String nrContrato;
            public String vlVenda;
            public String vlDevolucao;
            public String qtTotalClientes;
            public String qtClientesAtivosMes;
            public String flagMensal;
        }


        public  ContractJSON parse(String json) {
            return (ContractJSON) System.JSON.deserialize(json, ContractJSON.class);
        }
    }
    @HttpPatch
    global static String updateFaturamento(String contractId,Integer nrContrato, Boolean flagMensal, Double vlVenda, Double vlDevolucao,
                                              integer qtTotalClientes, integer qtClientesAtivosMes, Date dtEmissao ){
        RestRequest req = RestContext.request; 
        RestResponse res = RestContext.response;

        if (flagMensal == false){

            Opportunity oppInsert = [SELECT Id,Data_Emissao__c, Numero_Contrato_Univers__c, Valor_Vendas__c, Valor_Devolucao__c, 
                                             Quantidade_Total_Clientes__c, Quantidade_Cliente_Ativos_Mes__c 
                                             from Opportunity WHERE ContractId  =: contractId and Numero_Contrato_Univers__c =: nrContrato];

            //if (oppInsert.Numero_Contrato_Univers__c == null ){}

            oppInsert.Data_Emissao__c = dtEmissao;
            oppInsert.Numero_Contrato_Univers__c = nrContrato;
            oppInsert.Valor_Vendas__c = vlVenda;
            oppInsert.Valor_Devolucao__c = vlDevolucao;
            oppInsert.Quantidade_Total_Clientes__c = qtTotalClientes;
            oppInsert.Quantidade_Cliente_Ativos_Mes__c = qtClientesAtivosMes;

            upsert oppInsert ;

            return 'Faturamento';           

        } else if (flagMensal == true) {
            Contract contractInsert = [SELECT Id, Data_Emissao__c, Valor_Vendas__c, Valor_Devolucao__c, Quantidade_Total_Clientes__c,
                                             Quantidade_Clientes_Ativos_Mes__c  from Contract WHERE Id =: contractId];

            contractInsert.Data_Emissao__c = dtEmissao;
            contractInsert.Valor_Vendas__c = vlVenda;
            contractInsert.Valor_Devolucao__c = vlDevolucao;
            contractInsert.Quantidade_Total_Clientes__c = qtTotalClientes;
            contractInsert.Quantidade_Clientes_Ativos_Mes__c = qtClientesAtivosMes;

            upsert ContractInsert;

            /*List<Opportunity> listOpportunity = [select  ContractId, Id, Numero_Contrato_Univers__c, Data_Emissao__c, Valor_Vendas__c, 
                                                        Valor_Devolucao__c, Quantidade_Total_Clientes__c, Quantidade_Cliente_Ativos_Mes__c 
                                                        from Opportunity where ContractId =: contractId and  Numero_Contrato_Univers__c =: nrContrato ];

            for(Opportunity opp : listOpportunity){
                Opportunity oppDeleteDiario = new Opportunity ();
                oppDeleteDiario.Data_Emissao__c = dtEmissao;
                oppDeleteDiario.Valor_Vendas__c = vlVenda;
                oppDeleteDiario.Valor_Devolucao__c = vlDevolucao;
                oppDeleteDiario.Quantidade_Total_Clientes__c = qtTotalClientes;
                oppDeleteDiario.Quantidade_Cliente_Ativos_Mes__c = qtClientesAtivosMes;

                delete oppDeleteDiario; 
                return 'Deleted';
            }       */

            Opportunity oppDelete = [SELECT Id,Data_Emissao__c, Numero_Contrato_Univers__c, Valor_Vendas__c, Valor_Devolucao__c, 
                                             Quantidade_Total_Clientes__c, Quantidade_Cliente_Ativos_Mes__c 
                                             from Opportunity WHERE ContractId  =: contractId and Numero_Contrato_Univers__c =: nrContrato];

            //oppDelete.Data_Emissao__c = dtEmissao;
            //oppDelete.Numero_Contrato_Univers__c = nrContrato;
            oppDelete.Valor_Vendas__c = null;
            oppDelete.Valor_Devolucao__c = null;
            oppDelete.Quantidade_Total_Clientes__c = null;
            oppDelete.Quantidade_Cliente_Ativos_Mes__c = null;

            delete oppDelete;                        

            return 'Faturamento Mensal  Updated';
        }    
        return null;
    }
}

Hi everyone, I'm new to Salesforce and need to get a JSON to put inside my Apex class as per the code above. However it presents the following error:

Inner types are not allowed to have inner types

(in excerpt of the code:

public class Contract {
    public String idSalesForce;
    public String dtEmissao;
    public String nrContract;
    public String vlVenda;
    public String vlDevolution;
    public String qtTotalClients;
    public String qtClientActiveMes;
    public String flagMensal;
}

Can anyone help me with this problem?

up vote 4 down vote accepted

Your problem is that you have three classes in the same class - an inner class can't have another inner class inside of it. You can move the innermost class out, or into its own file.

Wont Compile:

@RestResource(urlMapping='/updateFaturamento/*')
global class contractFat {
    // inner class 
    public class ContractJSON {

        public List<Contract> Contract;
        // inner class inside an inner class - failure ! 
        public class Contract { 
            // ...
        }
    }
}

Will Compile:

@RestResource(urlMapping='/updateFaturamento/*')
global class contractFat {

    public class ContractJSON {

        public List<Contract> Contract;

    }

    public class Contract { 
        // ...
    }
}

As an aside, I'd be very careful about naming classes the same as Salesforce types - you might override the type and cause more problems down the line. Maybe something like ContractWrapper?

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.