+ Start a Discussion
Jose María Nicolás ArfelisJose María Nicolás Arfelis 

Checkbox should be filled automatically when comparing two objects

Hi all,

down vote favoritewe have the object Preinscripción containing records about which Postgraduate course someone applied for and paid. It contains the Name of the Applicant, the Postgraduate Course, the Identification Number, Status of the Preinscripción and a checkbox indicating whether a record with the same values Name of Applicant, Postgraduate Course and Identification Number exists or not in another object, the object Admission.
For example, let's say I have a record with data Name Pepe Flores, Postgraduate Course Cardiovascular Medicine, ID Number 1234567 in the object Preinscripción, if these values are also contained in the same fields in the object Admission, the checkbox should automatically be checked or populated.
Is it possible to make that work? is coding needed?.
Best Answer chosen by Jose María Nicolás Arfelis
sathishkumar periyasamysathishkumar periyasamy
Jose, Issue is "conlist" is list of sobject so you can't directly get field values from the collection. Please use below code

l.Estado_de_Solicitante_en_Admision__c = conlist[0].Estado_del_alumno__c;

My Recommention : Trigger is not bulkified.. current trigger will support one record at time. Please try to bulkify the trigger to support multiple records.

All Answers

Jose María Nicolás ArfelisJose María Nicolás Arfelis
There is no relationship between Preinscripción and Admission, but both have three fields in common.
Ankur Saini 9Ankur Saini 9
hi Jose María Nicolás Arfelis,

try this:
 
trigger OneRecordCanBeActive2 on Leader__c(before insert) {

    List<Contact> conlist= [select Email from Contact where Email =:Trigger.new[0].Email__c];
          if(conlist.size()>0){
             for(Leader__c l : Trigger.new){
              l.Active__c = true;                               
          }  
    }           
}


Thanks
Ankur Saini
http://mirketa.com
sathishkumar periyasamysathishkumar periyasamy
Hi Jose,

You can build trigger, If you have exact matching rule to identify the admissiona for Preinscripción. If you do then system will partially create link Admission and Preinscripción.

For Example :

Admission :
Name of Applicant     Postgraguate Cource   Email
Jose                           Medicine                       jose@hotmail.com

Preinscripción
Name of Applicant     Postgraguate Cource   Email
Jose                                                                 jose@hotmail.com

Above scenario trigger will not find matching. If the business ok to partial data have assocation then you can build trigger based on matching rule.
Jose María Nicolás ArfelisJose María Nicolás Arfelis
Thanks Sathish for your answer. I see that in a real situation, this mismatch shouldn't happen, as Name of the Applicant, Postgraduate Course, Email address and Identification number have to be populated. They are mandatory fields in the site we have, which content will appear in the web in the future.
If we use the trigger to find the matched records using the rule:

- Find me the records which have the same Name of the Applicant, Postgraduate Course, Email address and Identification Number in the object Admission as they are in the object Preinscripcion.
- If you find records set the checkbox Admission exists? of the corresponding Preinscripcion record to true

Trigger suggested by Ankur, would work right?
 
Jose María Nicolás ArfelisJose María Nicolás Arfelis
This is unfortunately not working:

User-added image
Jose María Nicolás ArfelisJose María Nicolás Arfelis
What is wrong in this code?:
 
trigger OneRecordCanBeActive2 on Preinscripci_n__c(before insert) {
	 
	    List<Admisi_n__c> conlist= [select Nombre_de_la_cuenta__c, Programa_Acad_mico__c, N_mero_de_identificaci_n__c, Correo_electr_nico__c, Estado_del_alumno__c from Admisi_n__c where Nombre_de_la_cuenta__c =:Trigger.new[0].Nombre_de_alumno__c and 
                                    Programa_Acad_mico__c =:Trigger.new[0].Programa_acad_mico_1__c and N_mero_de_identificaci_n__c =:Trigger.new[0].Numero_de_Identificacion__c and Correo_electr_nico__c =:Trigger.new[0].Correo_electronico__c];
	          if(conlist.size()>0){
	             for(Preinscripci_n__c l : Trigger.new){
	              l.Existe_en_Admision__c = true; 
                  l.Estado_de_Solicitante_en_Admision__c = conlist.Estado_del_alumno__c;
	          } 
	    }          
	}

I am trying now to set the value of the picklist Estado_de_Solicitante_en_Admision_c for object Preinscripcion to the value found in the picklist Estado_del_alumno_c in the object Admission but I get the error:
 
initial term of field expression must be a concrete sobject List
the error is pointing to the code line:
 
l.Estado_de_Solicitante_en_Admision__c = conlist.Estado_del_alumno__c;
can please somebody give me some tips to amend this?

 
sathishkumar periyasamysathishkumar periyasamy
Hi Jose, What is "Identification Number"? both object will have same value or diffrent value?
sathishkumar periyasamysathishkumar periyasamy
Jose, Issue is "conlist" is list of sobject so you can't directly get field values from the collection. Please use below code

l.Estado_de_Solicitante_en_Admision__c = conlist[0].Estado_del_alumno__c;

My Recommention : Trigger is not bulkified.. current trigger will support one record at time. Please try to bulkify the trigger to support multiple records.
This was selected as the best answer
Jose María Nicolás ArfelisJose María Nicolás Arfelis
Identification Number is for example the Number of your passport, say: C567899Y. If you also find the same Identification number in the Admission object (comparing with Preinscripcion) the checkbox should be filled. I will take in account your recommendation. Thank you.