function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
manjunath vivekmanjunath vivek 

What is the function of <strong> in the below code? and how does it work?

01 trigger populateFieldOnCase on Case (before insert){

02     Set<id>parentIds = new Set<id>();

03     for(Case acase:trigger.new){

04         parentIds.add(acase.project__c);

05     }

06     Map<id,parent__c> pro = new Map<id,parent__c>([select id,parentField__c from parent__c where idin :parentIds]);

07     for(case acase:trigger.new){

08         <strong>if(pro.get(acase.id) != null){</strong>

09             acase.childfield__c = pro.get(acase.id).parentField__c;

10         <strong>}</strong>

11     }

12 }
Best Answer chosen by manjunath vivek
Wizno @ ConfigeroWizno @ Configero
<strong> is actually not used for anything in apex. That is some HTML that was copy/pasted in by accident. Someone else may have been trying to outline that part of the code as an issue. 

All Answers

pconpcon
Line 6 generates a map of Id to Parent__c.  This is a standard method that the Apex language offers to build a map of object Id to the object.

Line 8 checks to see if the Id exists in the map.  If we did not do this and we tried to pull the data from the map and call parentField__c on it we would get a Null Pointer Exception (NPE).

I think your code should actually read:
 
trigger populateFieldOnCase on Case (before insert){
    Set<id>parentIds = new Set<id>();
    for (Case acase:trigger.new){
        parentIds.add(acase.project__c);
    }

    Map<id,parent__c> pro = new Map<id,parent__c>([
        select parentField__c
        from parent__c
        where id in :parentIds
    ]);

    for (case acase: trigger.new) {
        if (pro.get(acase.project__c) != null) {
            acase.childfield__c = pro.get(acase.project__c).parentField__c;
        }
    }
}
In your code you were checking the map pro for acase.Id which is not what the map is of.  The map is of case.Project__c to parent__c
Wizno @ ConfigeroWizno @ Configero
if (pro.get(acase.project__c) != null) {

vs

if ( pro.containsKey(acase.project__c) ) {

Just a suggestion, but I'd use the containsKey method rather than checking if it != null. Does the same thing but one looks a bit cleaner than the other. Again, just my personal preference as an OCD developer :-)
manjunath vivekmanjunath vivek
in the line 8 and 10 why <strong> is used, what is it for?
Wizno @ ConfigeroWizno @ Configero
<strong> is actually not used for anything in apex. That is some HTML that was copy/pasted in by accident. Someone else may have been trying to outline that part of the code as an issue. 
This was selected as the best answer
manjunath vivekmanjunath vivek
Thank you Wizno, I was not getting answer for <strong> anywhere,now I got the satisfactory answer. I am greatful to you.