• Sylvio Avilla
  • NEWBIE
  • 80 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 14
    Questions
  • 22
    Replies
Hello!

I'm having some trouble trying to display information on visualpage from a List < AggregateResult>

Here the code
public class print {
   
    
  private ApexPages.StandardController controller {get; set;}
  public SGAAF__Itinerario_Diario__c itinerario {get;set;} 
  public List<SGAAF__Viagem__c> viagens {get;set;} 
  public List <AggregateResult> nbrOfRecords {get;set;}
  
   public print(ApexPages.StandardController controller) {
 
        this.controller = controller;
        itinerario = (SGAAF__Itinerario_Diario__c)controller.getRecord();
 
    viagens = [ Select ID, Name, From SGAAF__Viagem__c
    Where SGAAF__Viagem__c.SGAAF__Itinerario_Diario__r.ID = :itinerario.ID];

 List <AggregateResult> nbrOfRecords = [ SELECT  SGAAF__motorista__r.Id mot , COUNT(Name) cnt   FROM  SGAAF__Viagem__c Where SGAAF__motorista__r.Id IN : motoristaSet
  and SGAAF__Viagem__c.SGAAF__Itinerario_Diario__r.ID = :itinerario.ID GROUP by SGAAF__motorista__r.Id   ];

 
 
  }



and page
 
<apex:page standardController="SGAAF__Itinerario_Diario__c" extensions="print" sidebar="false" renderAs="pdf"
    applyBodyTag="false" >

<apex:variable value="{!nbrOfRecords }" var="nbr"/> 

 <apex:outputText value="{!nbr['cnt']}" />

......
Can someone help me?

thanks

 
Hello Community,

When I try to upload a new package, receive the following error:
User-added image

The same thing happens when I try to change the Global Picklis itself:
User-added image

Does anyone knows why ?
Thanks
Hello,

I would like some help to bulkify the code bellow:
 
for (Trip__c trip : trigger.new )
{
	List<Trip__c> myTrips = [Select ID from Trip__c WHERE day__c =:trip.Day__c 
                            and driver__c =:trip.driver__c];

    .... rest of the code ....
}
Thanks
 
Hello,
I'm trying to solve a problem for a few days now and decided to ask for help, once again ... :S
Here is part of my code.
Basically I got a list:
List<CustomObject__c> lstMyObjects =  [Select ID, Name, DateTime1__c,DateTime2__c
                                     from CustomObject__c ];
Found the difference between all DateTime and Sorted It:
for(Integer i=0; i<lstMyObjects.size();i++){
            
           Long myValue = 0; 
          	
                Long dt1Long = (lstMyObjects[i+1].Field1__c.getTime())/1000;
                Long dt2Long = (lstMyObjects[i].Field2__c.getTime())/1000;
                myValue = (dt1Long-dt2Long)/60;
              	idDt1.put(myValue,lstMyObjects[i+1].ID);
              	idDt2.put(myValue,lstMyObjects[i].ID);

}

            myValues.add(myValue);
            (myValues.sort());
Now I've got the second greatest difference between DateTime value
Got the record ID
Now is the problem. For some reason, cannot find a way to retrieve the DateTime1__c value, using the ID, and receive the following error

"Initial term of field expression must be a concrete SObject: Id"


 
Id test = idDt1.get(myValues[myValues.size()-2]);
long time = test.DateTime1__c.getTime()/1000;

}
Don't know if it was clear enough, but hope someone could help me!

Thanks


 
Hello everyone,

Bellow is part of a code and I would like to know if someone could tell me why I’m receiving the error "List index out of bounds: -1"  for po.Interval2__c even though po.Size__c = 4 ( if I delete line po.Interval2__c =myValues[myValues.size()-2]; code runs ok )
 
List<Integer> myValues = new List<Integer>();
            myValues.add(myValue);
            (myValues.sort());
            
          	        
            po.Interval1__c = myValues[myValues.size()-1];
            po.Interval2__c =myValues[myValues.size()-2];
            po.Size__c = myValues.size();

Thanks

Sylvio
Hello Everyone,

I kindly ask for some help from the experts, regarding the following problem:

I need is somehow get all records with the same date (DATE) and subtract the field B from field A of the next record.
After that, create at least 2 variables, the first with the biggest value ( VAR 1 = Record 3.ID ) and so on (VAR 2 = Record 1.ID , VAR 3 = Record 2. ID).
I've made an example that I think will be easier to understand!
 
 DateABOppResultSort
Record 11/1/101020=B1-A220Var 2
Record 21/1/004050=B2-A310Var 3
Record 31/1/006070=B3-A160Var 1
Record 42/1/001020   
Record 52/1/003040   
Record 62/1/006070   

Does anyone can help whit that?

Thanks
Hello Everyone,

I'm facing a problem and would like some help to correct it
The following code works perfect on my developer account:


 
trigger ReagendarServico on Controle_de_Manuten_o__c (after update) {
    
    
  
   List<Controle_de_Manuten_o__c> co = [select Id,Veiculo__c,N_mero_de_Reagendamentos__c,Reagendamento_do_Servi_o__c,Status_do_Servi_o__c,Data_e_Hora_da_Solicita_o_do_Servi_o__c,Posicao__c,Solicitado_Por__c,Observa_o__c,Defeito__c,Componente__c from Controle_de_Manuten_o__c 
                                        where Id=:trigger.new];
    
          
    for (Controle_de_Manuten_o__c cont: co){
        if(cont.Status_do_Servi_o__c== 'Não Executado')
    {
        Controle_de_Manuten_o__c novoservico = new Controle_de_Manuten_o__c(
        Reagendamento_do_Servi_o__c =cont.ID,
        N_mero_de_Reagendamentos__c =cont.N_mero_de_Reagendamentos__c + 1,
        Data_e_Hora_da_Solicita_o_do_Servi_o__c = cont.Data_e_Hora_da_Solicita_o_do_Servi_o__c,
        Posicao__c = cont.Posicao__c ,
        Veiculo__c = cont.Veiculo__c,
        Solicitado_Por__c = cont.Solicitado_Por__c,
        Observa_o__c = cont.Observa_o__c,
        Defeito__c = cont.Defeito__c,
        Componente__c= cont.Componente__c,
        CompletarItensConstatados__c=true,
        Status_do_Servi_o__c = 'Reagendar'
        );
        insert novoservico;
        cont.Servi_o_Reagendado__c=true;
        cont.Status_do_Servi_o__c = 'Reagendado';
        update cont;
        novoservico.CompletarItensConstatados__c=false;
        update novoservico;        
    
    }
    }}
But when I use it on Production (my company’s environment) the following error is generated:

Update failed. First exception on row 0 with id a0ai000000BfT0qAAF; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SGAAF.ReagendarServico: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object (SGAAF): []
Error is in expression '{!SAVE}' in component <apex:commandButton> in page sgaaf:atualizaservicos: (SGAAF)
Thanks







 
Hi,

I am getting below error while uploading managed package:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com! 

Error ID: 203819700-4327 (-1569916658)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Is there a way around?

Thank you,

Sylvio
Hello,

I'm having trouble to build a test for the following code
 
public class AtualizaItemDoOrcamento {

    private List<Item_da_Compra__c> comp;
    private Id quoteId;

    public AtualizaItemDoOrcamento(ApexPages.StandardSetController c) {
        c.setPageSize(10);
        this.quoteId = ApexPages.currentPage().getParameters().get('id');
    }
     
   
   public List<Item_da_Compra__c> getcomp() {
       
        comp = [Select Id, Name, Quantidade_Orcada_Fornecedor_1__c, Status_do_Or_amento__c,Valor_Unitario_Fornecedor_1__c
                ,Fornecedor__c,Item__c, Marca__c ,C_digo_do_Produto__c from Item_da_Compra__c where Or_amento__c = :this.quoteId];
        return comp;
    }

    public pageReference save() {
        update comp;
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
            return ret.setRedirect(true);
    }

    public PageReference cancel() {
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
        return ret.setRedirect(true);
    }

}

Could anyone help me?

Thanks

Sylvio
Hello Everyone,

I'm having some trouble to get 75% coverage for the Trigger below:
 
trigger Overlap on Viagem__c  (before insert, before update) {
    
List<Viagem__c> overlaps=[select Name,Observa_o__c,Data_Chegada_Base__c,Hora_Saida_Base__c,Hora_Inicio_Linha__c,Hora_Fim_Linha__c,Hora_Chegada_Base__c,Data_da_Viagem__c,Motorista__c,Veiculo__c from Viagem__c
  where ((Hora_Saida_Base__c >:trigger.new[0].Hora_Saida_Base__c 
        AND Hora_Saida_Base__c < :trigger.new[0].Hora_Chegada_Base__c) OR
        (Hora_Chegada_Base__c  > :trigger.new[0].Hora_Saida_Base__c 
        AND Hora_Chegada_Base__c  < :trigger.new[0].Hora_Chegada_Base__c) OR
        (Hora_Saida_Base__c < :trigger.new[0].Hora_Saida_Base__c 
         AND Hora_Chegada_Base__c  > :trigger.new[0].Hora_Chegada_Base__c))
         AND Veiculo__c=:trigger.new[0].Veiculo__c 
         AND Data_da_Viagem__c=:trigger.new[0].Data_da_Viagem__c
             AND      Id !=:trigger.new[0].Id      ];

   if (!overlaps.isEmpty() )
{  
    if (trigger.new[0].Hora_Saida_Base__c == null|| trigger.new[0].Data_Chegada_Base__c <> trigger.new[0].Data_da_Viagem__c )
    {}
    Else {
        If (overlaps[0].Motorista__c == trigger.new[0].Motorista__c){
         
   trigger.new[0].addError('<span>Viagem com horário concorrente para o Veículo!<b></b></br><b>Viagem:</b></span>'
                           +overlaps[0].Name+'<span><b>.</b></br><b>Ficha:</b></span>'+overlaps[0].Observa_o__c
                           +'<span><b>.</b></br><b>Saída da Base:</b></span>'+overlaps[0].Hora_Saida_Base__c
                           +'<span><b>.</b></br><b>Chegada na Base:</b></span>'+overlaps[0].Hora_Chegada_Base__c
                           ,false);}
        
        Else{   //trigger.new[0].Duplicado__c = overlaps[0].Name;

   trigger.new[0].addError('<span>Viagem com horário concorrente para o Motorista!<b></b></br><b>Viagem:</b></span>'
                           +overlaps[0].Name+'<span><b>.</b></br><b>Ficha:</b></span>'+overlaps[0].Observa_o__c
                           +'<span><b>.</b></br><b>Saída da Base:</b></span>'+overlaps[0].Hora_Saida_Base__c
                           +'<span><b>.</b></br><b>Chegada na Base:</b></span>'+overlaps[0].Hora_Chegada_Base__c
                           ,false);}
   
    }
    
}        
}

The Test is this:
 
@isTest 
public class TestOverlap {
  static testMethod void TestOverlapComOverlap() {
      
       

            date mydate = date.parse('01/01/2015');
        
        Itinerario_Diario__c itinerario = new Itinerario_Diario__c (Dia__c = mydate );
        insert itinerario;
          
        Funcionarios__c motorista = new Funcionarios__c();
        insert motorista;
            
        Veiculo__c veiculo = new Veiculo__c ();
        insert veiculo;
   
      Viagem__c teste = new Viagem__c( 
      Itinerario_Diario__c = itinerario.ID,
      Hora_Saida_Base__c = '0100',
      Hora_Inicio_Linha__c = '0200',
      Hora_Fim_Linha__c = '0300',
      Hora_Chegada_Base__c = '0400',
      Motorista__c = motorista.ID,
      Veiculo__c = veiculo.ID  )   ;
      insert teste;
      
      
      try{
             
      Viagem__c testeduplicado = new Viagem__c( 
      Itinerario_Diario__c = itinerario.ID,
      Hora_Saida_Base__c = '0110',
      Hora_Inicio_Linha__c = '0210',
      Hora_Fim_Linha__c = '0310',
      Hora_Chegada_Base__c = '0410',
      Motorista__c = motorista.ID,
      Veiculo__c = motorista.ID);
      insert testeduplicado;
      
    }  
      catch(DmlException e) { 
    System.debug('The following exception has occurred: ' + e.getMessage());
      }        
  }

Cloud anyone point me the right direction

Thanks
 
Hello everyone!

I Have a strange problem with a Custom Object formula. It works perfectly, until I run the report. If the DateTime is between, let's say 01/01/2015 01:00 and 01/01/2015 01:09 ( that means if there is a 0 (zero) before the ":") the report returns an #Error!

Here the Formula:
DATETIMEVALUE(DATETIMEVALUE(TEXT(YEAR(SGAAF__data_da_viagem__c))+"-" +TEXT(MONTH(SGAAF__data_da_viagem__c))+"-" 
+TEXT(DAY(SGAAF__data_da_viagem__c))+" "+TEXT(VALUE(LEFT(SGAAF__Hora_Saida_Base__c, 2)))+ ":"+TEXT(VALUE(RIGHT(SGAAF__Hora_Saida_Base__c, 2)))+
":11")+SGAAF__GMT_horario_de_verao__c)
Custom Field:
Custom  Field

Report:

Report

Does anyone have a clue how can I fix it?

Thanks 

Sylvio
Hello Everyone,

To simplify, I would like  to create something similar to : a trigger to reverse the "Update Total Inventory When an Order is Placed" at the "Create a Warehouse App" example. That mans, when I delete a Invoice, it would subtract the amount of items on the inventory!
Reference : https://developer.salesforce.com/docs/atlas.en-us.workbook.meta/workbook/workflow_4.htm

Total_Inventory_Quantity  =   Total_Inventory_Quantity - Invoice_Quantity.

I could find something that is similar to what I want, at this post :http://salesforce.stackexchange.com/questions/22967/trigger-to-update-account-running-total-upon-change-to-any-child-custom-invoice, and end up with this code:
 
trigger Cancelar_Item_de_Nota on Itens_da_Nota_Fiscal__c (after delete, before update) {
    if(Trigger.isDelete) //&& (Trigger.isInsert || Trigger.isUpdate)){
       CancelarItemDaNota.atualizarQuantidadeemEstoque();
 
    }
 
public class CancelarItemDaNota {
         public static void atualizarQuantidadeemEstoque() {
  Set<Itens_da_Nota_Fiscal__c> invoices = new Set<Itens_da_Nota_Fiscal__c>();
  Set<Id> accountIds = new Set<Id>();
     List<Item__c> accounts = [SELECT Id, Quantidade_em_Estoque__c, (SELECT Id, Quantidade__c FROM Itens_da_Nota_Fiscal__r) FROM Item__c WHERE Id IN :accountIds];
        for(Itens_da_Nota_Fiscal__c invoice:invoices){
           // accountIds.add(invoice.Item__c);
        }
        for(Item__c acc:accounts){
           // acc.Quantidade_em_Estoque__c = 0;
            for(Itens_da_Nota_Fiscal__c invoice:acc.Itens_da_Nota_Fiscal__r){
                acc.Quantidade_em_Estoque__c -=  invoice.Quantidade__c ;
            }
        }
        update accounts;
    }

}
So,The code runs without any error but field is not updated. Nothing happens. 

Cloud anyone help me on this?

Thanks 



 
Hello Everyone,

I would like to create a simple trigger and prevent the user to add a new record that will overlap an existing record. 
  • The idea is that the same person couldn't do 2 things at the same time!
I read a lot and try to find an answer for my problem before star a discussion, but could't find it. 
This is the closest I could get to solve it:
// referene link https://developer.salesforce.com/forums/?id=906F00000008zTcIAI

// assuming the candidate is in myRec

List<MyRec__c> overlaps=[select Start_Date__c, End_Date__c, Business_Type__c 
 from MyRec__c
  where 
  (
      (Start_Date__c >= :myRec.Start_Date__c AND StartDate__c <= :myRec.Stop_Date__c) OR
      (Stop_Date__c  >= :myRec.Start_Date__c AND StopDate__c  <= :myRec.Stop_Date__c) OR
      (Start_Date__c <= :myRec.Start_Date__c AND StopDate__c  >= :myRec.Stop_Date__c)
  )
  and Business_Type__c=:myRec.Business_Type__c];

if (!overlaps.isEmpty())
{
   // error here
}
The problem is that when try to use it, receive the following error:

"Invalid bind expression type of Schema.SObjectField for column of type Datetime.

Can anyone tell me whats wrong?

Thanks

Hello,

 

would like some help on this problem.

I have 4 custom fields (Date/Time Let’s call it Date_Time__c) that must be filled on each trip (I have about 190 trips a day). So It´s a lot of typing, especially when the only thing I really need to type is the Time, because I have an object that already contains the day (Let's call it Day__c) I’m working with...

So I thought about creating another object (Time__c) and merge with a formula (Day__c and Time__c) objects, so I would save a lot of time. 

I know that there is no data type as TIME, so I thought to use a number and on this new formula change to TIME format to ""HH:MM"

Another thing is that sometimes I have trips that are finished on the day after it begins, so I would have to add a day in to the formula on those cases.

It is possible to do it with formula or I would have to do with Classes?

I hope I have made myself clear!

Thanks 

Sylvio

Hello!

I'm having some trouble trying to display information on visualpage from a List < AggregateResult>

Here the code
public class print {
   
    
  private ApexPages.StandardController controller {get; set;}
  public SGAAF__Itinerario_Diario__c itinerario {get;set;} 
  public List<SGAAF__Viagem__c> viagens {get;set;} 
  public List <AggregateResult> nbrOfRecords {get;set;}
  
   public print(ApexPages.StandardController controller) {
 
        this.controller = controller;
        itinerario = (SGAAF__Itinerario_Diario__c)controller.getRecord();
 
    viagens = [ Select ID, Name, From SGAAF__Viagem__c
    Where SGAAF__Viagem__c.SGAAF__Itinerario_Diario__r.ID = :itinerario.ID];

 List <AggregateResult> nbrOfRecords = [ SELECT  SGAAF__motorista__r.Id mot , COUNT(Name) cnt   FROM  SGAAF__Viagem__c Where SGAAF__motorista__r.Id IN : motoristaSet
  and SGAAF__Viagem__c.SGAAF__Itinerario_Diario__r.ID = :itinerario.ID GROUP by SGAAF__motorista__r.Id   ];

 
 
  }



and page
 
<apex:page standardController="SGAAF__Itinerario_Diario__c" extensions="print" sidebar="false" renderAs="pdf"
    applyBodyTag="false" >

<apex:variable value="{!nbrOfRecords }" var="nbr"/> 

 <apex:outputText value="{!nbr['cnt']}" />

......
Can someone help me?

thanks

 
Hello,

I would like some help to bulkify the code bellow:
 
for (Trip__c trip : trigger.new )
{
	List<Trip__c> myTrips = [Select ID from Trip__c WHERE day__c =:trip.Day__c 
                            and driver__c =:trip.driver__c];

    .... rest of the code ....
}
Thanks
 
Hello - Please advise how to write the following query.

Select all accounts that have at least one opportunity with the text "2016" in the name and also does not have any opportunities with the text "2017" and "2018" in the name. 

I tried my hand with reports and custom report types but as easy as this sounds no such luck.  I appreciate your help.

 
Hello everyone,

Bellow is part of a code and I would like to know if someone could tell me why I’m receiving the error "List index out of bounds: -1"  for po.Interval2__c even though po.Size__c = 4 ( if I delete line po.Interval2__c =myValues[myValues.size()-2]; code runs ok )
 
List<Integer> myValues = new List<Integer>();
            myValues.add(myValue);
            (myValues.sort());
            
          	        
            po.Interval1__c = myValues[myValues.size()-1];
            po.Interval2__c =myValues[myValues.size()-2];
            po.Size__c = myValues.size();

Thanks

Sylvio
Hello Everyone,

I kindly ask for some help from the experts, regarding the following problem:

I need is somehow get all records with the same date (DATE) and subtract the field B from field A of the next record.
After that, create at least 2 variables, the first with the biggest value ( VAR 1 = Record 3.ID ) and so on (VAR 2 = Record 1.ID , VAR 3 = Record 2. ID).
I've made an example that I think will be easier to understand!
 
 DateABOppResultSort
Record 11/1/101020=B1-A220Var 2
Record 21/1/004050=B2-A310Var 3
Record 31/1/006070=B3-A160Var 1
Record 42/1/001020   
Record 52/1/003040   
Record 62/1/006070   

Does anyone can help whit that?

Thanks
Hello Everyone,

I'm facing a problem and would like some help to correct it
The following code works perfect on my developer account:


 
trigger ReagendarServico on Controle_de_Manuten_o__c (after update) {
    
    
  
   List<Controle_de_Manuten_o__c> co = [select Id,Veiculo__c,N_mero_de_Reagendamentos__c,Reagendamento_do_Servi_o__c,Status_do_Servi_o__c,Data_e_Hora_da_Solicita_o_do_Servi_o__c,Posicao__c,Solicitado_Por__c,Observa_o__c,Defeito__c,Componente__c from Controle_de_Manuten_o__c 
                                        where Id=:trigger.new];
    
          
    for (Controle_de_Manuten_o__c cont: co){
        if(cont.Status_do_Servi_o__c== 'Não Executado')
    {
        Controle_de_Manuten_o__c novoservico = new Controle_de_Manuten_o__c(
        Reagendamento_do_Servi_o__c =cont.ID,
        N_mero_de_Reagendamentos__c =cont.N_mero_de_Reagendamentos__c + 1,
        Data_e_Hora_da_Solicita_o_do_Servi_o__c = cont.Data_e_Hora_da_Solicita_o_do_Servi_o__c,
        Posicao__c = cont.Posicao__c ,
        Veiculo__c = cont.Veiculo__c,
        Solicitado_Por__c = cont.Solicitado_Por__c,
        Observa_o__c = cont.Observa_o__c,
        Defeito__c = cont.Defeito__c,
        Componente__c= cont.Componente__c,
        CompletarItensConstatados__c=true,
        Status_do_Servi_o__c = 'Reagendar'
        );
        insert novoservico;
        cont.Servi_o_Reagendado__c=true;
        cont.Status_do_Servi_o__c = 'Reagendado';
        update cont;
        novoservico.CompletarItensConstatados__c=false;
        update novoservico;        
    
    }
    }}
But when I use it on Production (my company’s environment) the following error is generated:

Update failed. First exception on row 0 with id a0ai000000BfT0qAAF; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SGAAF.ReagendarServico: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object (SGAAF): []
Error is in expression '{!SAVE}' in component <apex:commandButton> in page sgaaf:atualizaservicos: (SGAAF)
Thanks







 
Hi,

I am getting below error while uploading managed package:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com! 

Error ID: 203819700-4327 (-1569916658)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Is there a way around?

Thank you,

Sylvio
Hello,

I'm having trouble to build a test for the following code
 
public class AtualizaItemDoOrcamento {

    private List<Item_da_Compra__c> comp;
    private Id quoteId;

    public AtualizaItemDoOrcamento(ApexPages.StandardSetController c) {
        c.setPageSize(10);
        this.quoteId = ApexPages.currentPage().getParameters().get('id');
    }
     
   
   public List<Item_da_Compra__c> getcomp() {
       
        comp = [Select Id, Name, Quantidade_Orcada_Fornecedor_1__c, Status_do_Or_amento__c,Valor_Unitario_Fornecedor_1__c
                ,Fornecedor__c,Item__c, Marca__c ,C_digo_do_Produto__c from Item_da_Compra__c where Or_amento__c = :this.quoteId];
        return comp;
    }

    public pageReference save() {
        update comp;
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
            return ret.setRedirect(true);
    }

    public PageReference cancel() {
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
        return ret.setRedirect(true);
    }

}

Could anyone help me?

Thanks

Sylvio
Hello Everyone,

I'm having some trouble to get 75% coverage for the Trigger below:
 
trigger Overlap on Viagem__c  (before insert, before update) {
    
List<Viagem__c> overlaps=[select Name,Observa_o__c,Data_Chegada_Base__c,Hora_Saida_Base__c,Hora_Inicio_Linha__c,Hora_Fim_Linha__c,Hora_Chegada_Base__c,Data_da_Viagem__c,Motorista__c,Veiculo__c from Viagem__c
  where ((Hora_Saida_Base__c >:trigger.new[0].Hora_Saida_Base__c 
        AND Hora_Saida_Base__c < :trigger.new[0].Hora_Chegada_Base__c) OR
        (Hora_Chegada_Base__c  > :trigger.new[0].Hora_Saida_Base__c 
        AND Hora_Chegada_Base__c  < :trigger.new[0].Hora_Chegada_Base__c) OR
        (Hora_Saida_Base__c < :trigger.new[0].Hora_Saida_Base__c 
         AND Hora_Chegada_Base__c  > :trigger.new[0].Hora_Chegada_Base__c))
         AND Veiculo__c=:trigger.new[0].Veiculo__c 
         AND Data_da_Viagem__c=:trigger.new[0].Data_da_Viagem__c
             AND      Id !=:trigger.new[0].Id      ];

   if (!overlaps.isEmpty() )
{  
    if (trigger.new[0].Hora_Saida_Base__c == null|| trigger.new[0].Data_Chegada_Base__c <> trigger.new[0].Data_da_Viagem__c )
    {}
    Else {
        If (overlaps[0].Motorista__c == trigger.new[0].Motorista__c){
         
   trigger.new[0].addError('<span>Viagem com horário concorrente para o Veículo!<b></b></br><b>Viagem:</b></span>'
                           +overlaps[0].Name+'<span><b>.</b></br><b>Ficha:</b></span>'+overlaps[0].Observa_o__c
                           +'<span><b>.</b></br><b>Saída da Base:</b></span>'+overlaps[0].Hora_Saida_Base__c
                           +'<span><b>.</b></br><b>Chegada na Base:</b></span>'+overlaps[0].Hora_Chegada_Base__c
                           ,false);}
        
        Else{   //trigger.new[0].Duplicado__c = overlaps[0].Name;

   trigger.new[0].addError('<span>Viagem com horário concorrente para o Motorista!<b></b></br><b>Viagem:</b></span>'
                           +overlaps[0].Name+'<span><b>.</b></br><b>Ficha:</b></span>'+overlaps[0].Observa_o__c
                           +'<span><b>.</b></br><b>Saída da Base:</b></span>'+overlaps[0].Hora_Saida_Base__c
                           +'<span><b>.</b></br><b>Chegada na Base:</b></span>'+overlaps[0].Hora_Chegada_Base__c
                           ,false);}
   
    }
    
}        
}

The Test is this:
 
@isTest 
public class TestOverlap {
  static testMethod void TestOverlapComOverlap() {
      
       

            date mydate = date.parse('01/01/2015');
        
        Itinerario_Diario__c itinerario = new Itinerario_Diario__c (Dia__c = mydate );
        insert itinerario;
          
        Funcionarios__c motorista = new Funcionarios__c();
        insert motorista;
            
        Veiculo__c veiculo = new Veiculo__c ();
        insert veiculo;
   
      Viagem__c teste = new Viagem__c( 
      Itinerario_Diario__c = itinerario.ID,
      Hora_Saida_Base__c = '0100',
      Hora_Inicio_Linha__c = '0200',
      Hora_Fim_Linha__c = '0300',
      Hora_Chegada_Base__c = '0400',
      Motorista__c = motorista.ID,
      Veiculo__c = veiculo.ID  )   ;
      insert teste;
      
      
      try{
             
      Viagem__c testeduplicado = new Viagem__c( 
      Itinerario_Diario__c = itinerario.ID,
      Hora_Saida_Base__c = '0110',
      Hora_Inicio_Linha__c = '0210',
      Hora_Fim_Linha__c = '0310',
      Hora_Chegada_Base__c = '0410',
      Motorista__c = motorista.ID,
      Veiculo__c = motorista.ID);
      insert testeduplicado;
      
    }  
      catch(DmlException e) { 
    System.debug('The following exception has occurred: ' + e.getMessage());
      }        
  }

Cloud anyone point me the right direction

Thanks
 
Hello everyone!

I Have a strange problem with a Custom Object formula. It works perfectly, until I run the report. If the DateTime is between, let's say 01/01/2015 01:00 and 01/01/2015 01:09 ( that means if there is a 0 (zero) before the ":") the report returns an #Error!

Here the Formula:
DATETIMEVALUE(DATETIMEVALUE(TEXT(YEAR(SGAAF__data_da_viagem__c))+"-" +TEXT(MONTH(SGAAF__data_da_viagem__c))+"-" 
+TEXT(DAY(SGAAF__data_da_viagem__c))+" "+TEXT(VALUE(LEFT(SGAAF__Hora_Saida_Base__c, 2)))+ ":"+TEXT(VALUE(RIGHT(SGAAF__Hora_Saida_Base__c, 2)))+
":11")+SGAAF__GMT_horario_de_verao__c)
Custom Field:
Custom  Field

Report:

Report

Does anyone have a clue how can I fix it?

Thanks 

Sylvio
Hello Everyone,

To simplify, I would like  to create something similar to : a trigger to reverse the "Update Total Inventory When an Order is Placed" at the "Create a Warehouse App" example. That mans, when I delete a Invoice, it would subtract the amount of items on the inventory!
Reference : https://developer.salesforce.com/docs/atlas.en-us.workbook.meta/workbook/workflow_4.htm

Total_Inventory_Quantity  =   Total_Inventory_Quantity - Invoice_Quantity.

I could find something that is similar to what I want, at this post :http://salesforce.stackexchange.com/questions/22967/trigger-to-update-account-running-total-upon-change-to-any-child-custom-invoice, and end up with this code:
 
trigger Cancelar_Item_de_Nota on Itens_da_Nota_Fiscal__c (after delete, before update) {
    if(Trigger.isDelete) //&& (Trigger.isInsert || Trigger.isUpdate)){
       CancelarItemDaNota.atualizarQuantidadeemEstoque();
 
    }
 
public class CancelarItemDaNota {
         public static void atualizarQuantidadeemEstoque() {
  Set<Itens_da_Nota_Fiscal__c> invoices = new Set<Itens_da_Nota_Fiscal__c>();
  Set<Id> accountIds = new Set<Id>();
     List<Item__c> accounts = [SELECT Id, Quantidade_em_Estoque__c, (SELECT Id, Quantidade__c FROM Itens_da_Nota_Fiscal__r) FROM Item__c WHERE Id IN :accountIds];
        for(Itens_da_Nota_Fiscal__c invoice:invoices){
           // accountIds.add(invoice.Item__c);
        }
        for(Item__c acc:accounts){
           // acc.Quantidade_em_Estoque__c = 0;
            for(Itens_da_Nota_Fiscal__c invoice:acc.Itens_da_Nota_Fiscal__r){
                acc.Quantidade_em_Estoque__c -=  invoice.Quantidade__c ;
            }
        }
        update accounts;
    }

}
So,The code runs without any error but field is not updated. Nothing happens. 

Cloud anyone help me on this?

Thanks 



 
Hello Everyone,

I would like to create a simple trigger and prevent the user to add a new record that will overlap an existing record. 
  • The idea is that the same person couldn't do 2 things at the same time!
I read a lot and try to find an answer for my problem before star a discussion, but could't find it. 
This is the closest I could get to solve it:
// referene link https://developer.salesforce.com/forums/?id=906F00000008zTcIAI

// assuming the candidate is in myRec

List<MyRec__c> overlaps=[select Start_Date__c, End_Date__c, Business_Type__c 
 from MyRec__c
  where 
  (
      (Start_Date__c >= :myRec.Start_Date__c AND StartDate__c <= :myRec.Stop_Date__c) OR
      (Stop_Date__c  >= :myRec.Start_Date__c AND StopDate__c  <= :myRec.Stop_Date__c) OR
      (Start_Date__c <= :myRec.Start_Date__c AND StopDate__c  >= :myRec.Stop_Date__c)
  )
  and Business_Type__c=:myRec.Business_Type__c];

if (!overlaps.isEmpty())
{
   // error here
}
The problem is that when try to use it, receive the following error:

"Invalid bind expression type of Schema.SObjectField for column of type Datetime.

Can anyone tell me whats wrong?

Thanks
Hello all,

I am struggling to write a Test Class for the following trigger and static class that synchronizes portal users with contact record data:
trigger UpdateContactFromPortalUser on User (after update) {
    //We only want to run on the single item that the user edited 
    if (Trigger.new.size()==1) 
    { 
        User u =_ Trigger.new[0]; 
        //And only if it's a portal user 
        if (u.ContactId!=null) { 
            UpdateContactFromPortalUser.updateContacts(u.Id); 
        } 
    } 
}
global class UpdateContactFromPortalUser { 
    @future 
    public static void updateContacts(String userId) {
        User u = [select ContactId,Email,FirstName,LastName,Title
                    from User
                    where Id=:userId];

        if (u!=null && u.ContactId!=null) {
            Contact c = new Contact(Id=u.ContactId,Email=u.Email,FirstName=u.FirstName,LastName=u.LastName,Title=u.Title);
            update c; 
        }
    }
}
Here is my test class code:
 
@isTest
private class UpdateContactFromPortalUserTest {

static testMethod void testUpdateContacts() {

        Test.startTest(); 
        
        User u = [select Id,ContactId,FirstName from User where ContactId<>'' limit 1]; 

        u.FirstName='Bar';
         
        update u; 

        Test.stopTest(); 

        Contact c = [select FirstName from Contact where Id=:u.ContactId]; 
        System.assertEquals(c.FirstName,u.FirstName); 
    }
}

I am getting no code coverage when I runt the test.  Can someone help point me to what I am missing?

Thanks in advance for any help.