• Felipe Senler
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hello community:

You see, i have this issue from a previous problem on another post though, since ive upgraded my solution a bit more, but heres my issue:
I need that from a for loop on two users, user1 (Original object) and User2 object to dinamically itarate against, to get all users, this actually does manage to grant me all users from the Object user, but now i need to get only a few names out of it, heres the code ive figured so far:
for(User user2:user1)//Iterates to get all users available
            {   
                	String usua = user2.name;
                	System.debug('Nombres de usuarios:'+usua);
                    String usuaid = user2.id;//gets the id for each user retrieved
                    String a = usuaid;
                   //Assigns the Id of the users into 'a' as variable (Orginal,right?)
            		Id usuarioid = Id.valueOf(a);//turns the id (String) as Id
                    System.debug('Id usuario: '+usuarioid);
            }
To sum up, i need to basically, from this loop that gets me all users and id's from user to be able to retrieve certain users out of it, been trying to figure this out, but im kinda stuck for the time being.
Any help is appreciated.
Greetings community, you see, i need your help with this trigger, let me context first:

What i exactly need for the trigger, is that from a multipicklist, associate its values to a user id to send a email for the associated user id from User, because of a helperclass called "emailHelper", that after a few modifications it requires a user id that lets it send a template email to the users that the user id has referes to.

Trigger is here below:
trigger EventosAOportunidadv3 on Event (after insert) {

    List<Opportunity> op = [SELECT Owner.id, Owner.Name, Equipo__c 
              				From Opportunity];
    
    for(Event eve:Trigger.new)//Recorre el evento
    {      
        System.debug('Tamaño Trigger: '+Trigger.new.size());
		system.debug('Cantidad de oportunidades: '+op.size());
        If((eve.Subject == 'Reunión'))//Verifies the subject is reunion
        {
            emailHelper e = new emailHelper();
            
            String[] tmpString = op.get(0).Equipo__c.split(';');
			For(String s : tmpString)//Iterates along the custom object (multipicklist)
   			system.debug(s);
            
           //Here i need to bring the users from User and retrieve its id's i did that as well, but....
    User user1 = [Select name,id from user];

            if((op.get(0).equipo__c).contains(user.name)&&(op.get(0).equipo__c!=null))
            {
            
            String usua = user1.ownerid;//For testing got the owner's id related to the event, but  list has more than 1 row for assignment, if limited the user up to one the code DOES Work and ran out of options
            String a = usua;
            Id usuarioid = Id.valueOf(a);//and turn its string value onto a ID
            System.debug ('Por Felipe');
            e.sendEmail(usuarioid);
            	else
                {
                    System.debug('User not valid');
                    //e.sendmail(usuarioid);
                }
            }    
           }
         }
}
emailHelper class, if needed:
// In a separate class so that it can be used elsewhere
Global class emailHelper {
    
public void sendEmail(ID usuarioid) {

  //New instance of a single email message

 Messaging.SingleEmailMessage mail =

            new Messaging.SingleEmailMessage();

// Who you are sending the email to
    mail.setTargetObjectId(usuarioid); 
	//System.debug('Mail de user:'+user);
    // The email template ID used for the email

   mail.setTemplateId('00X36000000NQvEEAW');   

   mail.setBccSender(false);

   mail.setUseSignature(false);

   mail.setSenderDisplayName('HR Recruiting');

   mail.setSaveAsActivity(false); 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    } 

}


E.g: If from the multipicklist i pick the values "Felipe" and "Andres", need to associate those picklist values to a actual user ID from two people stored on the User object,in this case called "Felipe" and "Andres.

I know its not very bulky safe, but any help would be appreciated.
Thanks in advance!
Phillip.
Greetings, Ive just started a few days ago with Apex by work as a junior developer at the moment, heres my issue:

This trigger needs to transfer Integer values from a custom Object called Encuesta__c(Survey__c) with its a custom object, to three custom fields (Num_Prom_Cobr__c,Num_Prom_Perp__c,Num_Prom_Sin__c) from Account after being fired.

Heres the trigger code called traspasoValoresListas (transferListValues):

trigger traspasoValoresListas on Encuesta__c (before insert , before update) {

Encuesta__c[] encu = Trigger.new;

Integer sin; /*These three Integers are to contain the upcoming values of APEX class called
Integer cob; ConvertirStringValores with functions that converts the values of a Seleccion list into Integers*/
Integer per;

for (Integer i=0;i<encu.size();i++)
{
     sin=ConvertirStringValores.convertirListasSiniestros(encu[i]);//Turns the value Selectionlist called Siniestros(Fires)(String) to Integer
     per=ConvertirStringValores.convertirListasPercepcion(encu[i]);//Turns the value Selectionlist called Percepcion(Perception)(String) to Integer
     cob=ConvertirStringValores.convertirListasCobranza(encu[i]);//Turns the value Selectionlist called Cobranza(Collections)(String) to Integer
    //All of these values coming from the Custom Object Encuesta__c assigned as encu;
}
//The code sadly goes downhill from here
Account a = [SELECT Num_Prom_Cobr__c,Num_Prom_Perp__c,Num_Prom_Sin__c
                   FROM Account];

a.Num_Prom_Cobr__c=cob;
a.Num_Prom_Perp__c=per;
a.Num_Prom_Sin__c=sin;

update a;
}

Any help is highly appreciated!
Felipe.
Hello community:

You see, i have this issue from a previous problem on another post though, since ive upgraded my solution a bit more, but heres my issue:
I need that from a for loop on two users, user1 (Original object) and User2 object to dinamically itarate against, to get all users, this actually does manage to grant me all users from the Object user, but now i need to get only a few names out of it, heres the code ive figured so far:
for(User user2:user1)//Iterates to get all users available
            {   
                	String usua = user2.name;
                	System.debug('Nombres de usuarios:'+usua);
                    String usuaid = user2.id;//gets the id for each user retrieved
                    String a = usuaid;
                   //Assigns the Id of the users into 'a' as variable (Orginal,right?)
            		Id usuarioid = Id.valueOf(a);//turns the id (String) as Id
                    System.debug('Id usuario: '+usuarioid);
            }
To sum up, i need to basically, from this loop that gets me all users and id's from user to be able to retrieve certain users out of it, been trying to figure this out, but im kinda stuck for the time being.
Any help is appreciated.
Greetings community, you see, i need your help with this trigger, let me context first:

What i exactly need for the trigger, is that from a multipicklist, associate its values to a user id to send a email for the associated user id from User, because of a helperclass called "emailHelper", that after a few modifications it requires a user id that lets it send a template email to the users that the user id has referes to.

Trigger is here below:
trigger EventosAOportunidadv3 on Event (after insert) {

    List<Opportunity> op = [SELECT Owner.id, Owner.Name, Equipo__c 
              				From Opportunity];
    
    for(Event eve:Trigger.new)//Recorre el evento
    {      
        System.debug('Tamaño Trigger: '+Trigger.new.size());
		system.debug('Cantidad de oportunidades: '+op.size());
        If((eve.Subject == 'Reunión'))//Verifies the subject is reunion
        {
            emailHelper e = new emailHelper();
            
            String[] tmpString = op.get(0).Equipo__c.split(';');
			For(String s : tmpString)//Iterates along the custom object (multipicklist)
   			system.debug(s);
            
           //Here i need to bring the users from User and retrieve its id's i did that as well, but....
    User user1 = [Select name,id from user];

            if((op.get(0).equipo__c).contains(user.name)&&(op.get(0).equipo__c!=null))
            {
            
            String usua = user1.ownerid;//For testing got the owner's id related to the event, but  list has more than 1 row for assignment, if limited the user up to one the code DOES Work and ran out of options
            String a = usua;
            Id usuarioid = Id.valueOf(a);//and turn its string value onto a ID
            System.debug ('Por Felipe');
            e.sendEmail(usuarioid);
            	else
                {
                    System.debug('User not valid');
                    //e.sendmail(usuarioid);
                }
            }    
           }
         }
}
emailHelper class, if needed:
// In a separate class so that it can be used elsewhere
Global class emailHelper {
    
public void sendEmail(ID usuarioid) {

  //New instance of a single email message

 Messaging.SingleEmailMessage mail =

            new Messaging.SingleEmailMessage();

// Who you are sending the email to
    mail.setTargetObjectId(usuarioid); 
	//System.debug('Mail de user:'+user);
    // The email template ID used for the email

   mail.setTemplateId('00X36000000NQvEEAW');   

   mail.setBccSender(false);

   mail.setUseSignature(false);

   mail.setSenderDisplayName('HR Recruiting');

   mail.setSaveAsActivity(false); 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    } 

}


E.g: If from the multipicklist i pick the values "Felipe" and "Andres", need to associate those picklist values to a actual user ID from two people stored on the User object,in this case called "Felipe" and "Andres.

I know its not very bulky safe, but any help would be appreciated.
Thanks in advance!
Phillip.
Greetings, Ive just started a few days ago with Apex by work as a junior developer at the moment, heres my issue:

This trigger needs to transfer Integer values from a custom Object called Encuesta__c(Survey__c) with its a custom object, to three custom fields (Num_Prom_Cobr__c,Num_Prom_Perp__c,Num_Prom_Sin__c) from Account after being fired.

Heres the trigger code called traspasoValoresListas (transferListValues):

trigger traspasoValoresListas on Encuesta__c (before insert , before update) {

Encuesta__c[] encu = Trigger.new;

Integer sin; /*These three Integers are to contain the upcoming values of APEX class called
Integer cob; ConvertirStringValores with functions that converts the values of a Seleccion list into Integers*/
Integer per;

for (Integer i=0;i<encu.size();i++)
{
     sin=ConvertirStringValores.convertirListasSiniestros(encu[i]);//Turns the value Selectionlist called Siniestros(Fires)(String) to Integer
     per=ConvertirStringValores.convertirListasPercepcion(encu[i]);//Turns the value Selectionlist called Percepcion(Perception)(String) to Integer
     cob=ConvertirStringValores.convertirListasCobranza(encu[i]);//Turns the value Selectionlist called Cobranza(Collections)(String) to Integer
    //All of these values coming from the Custom Object Encuesta__c assigned as encu;
}
//The code sadly goes downhill from here
Account a = [SELECT Num_Prom_Cobr__c,Num_Prom_Perp__c,Num_Prom_Sin__c
                   FROM Account];

a.Num_Prom_Cobr__c=cob;
a.Num_Prom_Perp__c=per;
a.Num_Prom_Sin__c=sin;

update a;
}

Any help is highly appreciated!
Felipe.