• Pedro Salles
  • NEWBIE
  • 90 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 5
    Replies
Hello, I'm working on a production org and need to delete apex classes and objects, however my code coverage is at 56% and I can not raise any other class into the production environment. It's 2012, and I can not find a reason why she lost coverage other than updates from salesforce. Has anyone experienced this situation know how to fix this problem?

Thanks

Pedro
Hi,

I have a Get method that receives data through a URL:
 
@RestResource(urlMapping='/Contract/*')
global  class ContractREST {
    
    @HttpGet
    global static String getContratos() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String ContractId= req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

        Contract result =  [SELECT Id , Regra_Separacao_Cartao__c, Origem_Contrato__c   
                                      from Contract where Id =: ContractId ];       

.
.
.
        JSONGenerator gen = JSON.createGenerator(true);    
        gen.writeStartObject();             
        
        gen.writeStringField('Id',result.Id);

        gen.writeEndObject();
        
        String jsonS = gen.getAsString();
             
        return contractJSON;
    }
  
}

I need to create a test class for my class, however I can not pass any parameters to the method because using GET does not accept.

Could someone help me with this question?

Thanks
Hello everyone,
I am new to SF and am trying to solve the following problem:
I have a JSON and I need to pass the data to a list, then use it as my class parameter.
I've managed to pass JSON to a List, but when I put it in the class, it throws the following error:

"global methods do not support parameter type of List<contractFat.Contract>"

My code:
 
@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(List<Contract> Contratos)
    {
    RestRequest req = RestContext.request; 
    RestResponse res = RestContext.response;
Can anyone help me with this problem?

Thanks
 
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;
    }
}
Error: Inner types are not allowed to have inner types

This error is displayed in the Contract class.
I tried to separate the classes, but still the error persists.
Can anyone help me with this problem?

Thanks

 
Hello everyone.

I'm new to Salesforce and need to create authentication for a Webservice call.
I read in some content and in the Trailhead itself ways of doing this authentication, but the only one I have managed to do so far is authentication via SOAP.
My calls will all be REST.

Now my points of doubt:
Could I use this SOAP authentication to open a session and then use REST calls to exchange information?
Or would it be better for me to perform REST authentication to start the information exchange?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>login@example.com</urn:username>
         <urn:password>passowordcQZYyxtJFwSDrmb4eSp4B3X</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>
My response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <loginResponse>
         <result>
            <metadataServerUrl>https://cs71.salesforce.com/services/Soap/m/43.0/00D4D0000000Ndl</metadataServerUrl>
            <passwordExpired>false</passwordExpired>
            <sandbox>true</sandbox>
            <serverUrl>https://cs71.salesforce.com/services/Soap/c/43.0/00D4D0000000Ndl/0DF4D00000000Kf</serverUrl>
            <sessionId>00D4D0000000Ndl!ARUAQNbw2wA6Kl5mrvQOsGrKloCPYGg.u1OQVmLg68DSYUbk5rLrUrX60S820uAMGVRMeT0x182P4OlgbO24hZIJ0</sessionId>
            <userId>0054D000000uhEdQAI</userId>
            <userInfo>
               <accessibilityMode>false</accessibilityMode>
               <chatterExternal>false</chatterExternal>
               <currencySymbol>R$</currencySymbol>
               <orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit>
               <orgDefaultCurrencyIsoCode>BRL</orgDefaultCurrencyIsoCode>
               <orgDefaultCurrencyLocale>pt_BR</orgDefaultCurrencyLocale>
               <orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments>
               <orgHasPersonAccounts>false</orgHasPersonAccounts>
               <organizationId>00D4D0000000NdlUAE</organizationId>
               <organizationMultiCurrency>false</organizationMultiCurrency>
               <organizationName>Raia Drogasil S/A</organizationName>
               <profileId>00eA0000000lgNeIAI</profileId>
               <roleId xsi:nil="true"/>
               <sessionSecondsValid>7200</sessionSecondsValid>
               <userDefaultCurrencyIsoCode xsi:nil="true"/>
               <userEmail>example@example.com</userEmail>
               <userFullName>Pedro Salles</userFullName>
               <userId>0054D000000uhEdQAI</userId>
               <userLanguage>pt_BR</userLanguage>
               <userLocale>pt_BR</userLocale>
               <userName>Pedro Salles</userName>
               <userTimeZone>America/Sao_Paulo</userTimeZone>
               <userType>Standard</userType>
               <userUiSkin>Theme3</userUiSkin>
            </userInfo>
         </result>
      </loginResponse>
   </soapenv:Body>
</soapenv:Envelope>
Can someone help me?

Thanks
I created a trigger to invoke an apex class. The trigger is activated every time a contract is entered, i needed to get the ID of this contract, put it on the trigger and send it to my apex class, where i will conduct a query to send information to a partner Webservice.
I'm not finding content for this subject in Trailhead and developer.salesforce.
Could someone help me with this problem?

Thank you
Hello,
I am creating a code for an apex class to be triggered by a trigger.
Apex class:
public class contractCallout {@future (callout=true)
    public static void PostCallout(String Id) {        
        
        Contract result =  [SELECT Id from contract where Id = '8004D000000HAdIQAW'];
        
        JSONGenerator gen = JSON.createGenerator(true);    
        gen.writeStartObject();      
        gen.writeStringField('Id', result.Id);
        /*gen.writeStringField('Origem_Contrato__c',result.Origem_Contrato__c);
        gen.writeStringField('Cotacao__r.Contact.FirstName',result.Cotacao__r.Contact.FirstName);
        gen.writeStringField('Cotacao__r.Contact.LastName',result.Cotacao__r.Contact.LastName);    */    
        gen.writeEndObject();    
        String jsonS = gen.getAsString();
        System.debug('jsonMaterials'+jsonS);
        
        // Sening the http body with JSON 
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        request.setBody(jsonS);
        HttpResponse response = http.send(request);
        // Parse the JSON response
        if (response.getStatusCode() != 201) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }   
    } 
}

Trigger:
trigger CalloutTrigger on Contract (after insert, after update) {  
   contractCallout.PostCallout();  
 }
My trigger has the following error:
​“Line: 1, Column: 2 Unexpected token 'trigger' “

Could someone help me to test this trigger? I did not find a way for this.

Thanks
 
Hello,

I'm new to Salesforce and I have the following situation: Every time a contract is validated within Salesforce, I need to gather all the information that is within this contract and send it to an external partner system. Would you like to know the best way to do this in an integration?

Thanks
I am trying to create a service that exposes data from Salesforce to an external system.
 found several features to create a web service.
However, I can not find how to structure the actual http POST for Salesforce on another system.
I read several materials talking about callout.
Would it be the best way to do this service?
Hi, 

I have a problem with my code:

public class contractCallout {@future (callout=true)
    public static void PostCallout(String Id) {        
        
        Contract result =  [SELECT Id from contract where Id = '8004D000000HAdIQAW'];
        
        JSONGenerator gen = JSON.createGenerator(true);    
        gen.writeStartObject();      
        gen.writeStringField('Id', result.Id);
        /*gen.writeStringField('Origem_Contrato__c',result.Origem_Contrato__c);
        gen.writeStringField('Cotacao__r.Contact.FirstName',result.Cotacao__r.Contact.FirstName);
        gen.writeStringField('Cotacao__r.Contact.LastName',result.Cotacao__r.Contact.LastName);    */    
        gen.writeEndObject();    
        String jsonS = gen.getAsString();
        System.debug('jsonMaterials'+jsonS);
        
        // Sening the http body with JSON 
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        request.setBody(jsonS);
        HttpResponse response = http.send(request);
        // Parse the JSON response
        if (response.getStatusCode() != 201) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }   
    } 
}


when I am going to take a test, it presents the following error: static can only be used on methods of a top level type 

Can someone help me?

Thanks
Hello,

I'm new to salesforce and need to develop an apex class that captures contract data and sends it to a partner Webservice. It was recommended to use callout with triggers, but in the materials I found, it does not have much content on how to do it.

Can anybody help me?

Thank you
Hello everyone,

I need to send data to a partner webservice through a callout. This will be done through a trigger that invokes this class.

Thanks

Hello everyone. I need to make available to a partner webservice information from within the salesforce via REST calls.

Best regards.
Hello, I'm working on a production org and need to delete apex classes and objects, however my code coverage is at 56% and I can not raise any other class into the production environment. It's 2012, and I can not find a reason why she lost coverage other than updates from salesforce. Has anyone experienced this situation know how to fix this problem?

Thanks

Pedro
Hi,

I have a Get method that receives data through a URL:
 
@RestResource(urlMapping='/Contract/*')
global  class ContractREST {
    
    @HttpGet
    global static String getContratos() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String ContractId= req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

        Contract result =  [SELECT Id , Regra_Separacao_Cartao__c, Origem_Contrato__c   
                                      from Contract where Id =: ContractId ];       

.
.
.
        JSONGenerator gen = JSON.createGenerator(true);    
        gen.writeStartObject();             
        
        gen.writeStringField('Id',result.Id);

        gen.writeEndObject();
        
        String jsonS = gen.getAsString();
             
        return contractJSON;
    }
  
}

I need to create a test class for my class, however I can not pass any parameters to the method because using GET does not accept.

Could someone help me with this question?

Thanks
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;
    }
}
Error: Inner types are not allowed to have inner types

This error is displayed in the Contract class.
I tried to separate the classes, but still the error persists.
Can anyone help me with this problem?

Thanks

 
Hi, 

I have a problem with my code:

public class contractCallout {@future (callout=true)
    public static void PostCallout(String Id) {        
        
        Contract result =  [SELECT Id from contract where Id = '8004D000000HAdIQAW'];
        
        JSONGenerator gen = JSON.createGenerator(true);    
        gen.writeStartObject();      
        gen.writeStringField('Id', result.Id);
        /*gen.writeStringField('Origem_Contrato__c',result.Origem_Contrato__c);
        gen.writeStringField('Cotacao__r.Contact.FirstName',result.Cotacao__r.Contact.FirstName);
        gen.writeStringField('Cotacao__r.Contact.LastName',result.Cotacao__r.Contact.LastName);    */    
        gen.writeEndObject();    
        String jsonS = gen.getAsString();
        System.debug('jsonMaterials'+jsonS);
        
        // Sening the http body with JSON 
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        request.setBody(jsonS);
        HttpResponse response = http.send(request);
        // Parse the JSON response
        if (response.getStatusCode() != 201) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }   
    } 
}


when I am going to take a test, it presents the following error: static can only be used on methods of a top level type 

Can someone help me?

Thanks
Hello,

I'm new to salesforce and need to develop an apex class that captures contract data and sends it to a partner Webservice. It was recommended to use callout with triggers, but in the materials I found, it does not have much content on how to do it.

Can anybody help me?

Thank you