• SambitNayak
  • NEWBIE
  • 40 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 8
    Replies
Hi,
I have added opportunity as a lookup in contact. I want my description on contact to be updated with the related opportunity's stage name. My following code is not working. Please let me know where I went wrong:

trigger populateOppStage on Contact (before insert, before update) {
   Set<ID> opps = New Set<ID>();
    for (contact con:trigger.new){
        opps.add(con.opportunity__r.Id);
    }
    Map<Id, String> mapOppToStage = New Map<Id, String>();
    for(opportunity opp:[SELECT ID, stagename 
                      FROM opportunity WHERE ID IN:opps]){
        mapOppToStage.put(opp.id, opp.stagename);
    }

    for (contact c:trigger.new){
        if(mapOppToStage.containsKey(c.opportunity__r.Id)){
                c.Description= mapOppToStage.get(c.Opportunity__r.id);
        }
    }
}

Hi,
I have the contact object. Work Allocation is a custom child object of Contact.
How do I iterate over these child records without using SELECT query inside the FOR loop.
My Trigger handler code is here. Although it's working fine, I know it's not bulkified. Please help:

 

    public static void checkWorkAlloc(List<Work_Allocation__c> workAllocList){
        for (Work_Allocation__c wk : workAllocList){
            //Collect the work allocation records under the parent Contact in an array
            Work_Allocation__c[] wkAlList=[SELECT Id, Start_Date__c, End_Date__c FROM Work_Allocation__c WHERE Contact_Resource__c =: wk.Contact_Resource__c];
            
            if(wkAlList.size()>0){
                for (Integer i=0; i < wkAlList.size(); i++){
                Work_Allocation__c workAlloc1=wkAlList[i];

Hi,
I have Contact object with Team Member as child object. The sum of all the allocations of Team Members under a certain contact cant exceed 100.  
This helper class is not working properly. Please advise:

 

public class TrigAllocToTeamHandler {
    public static void chkTeamAlloc(List<Team_Member__c> teamList){
        
        for(Team_Member__c tm:teamList){
        List <Team_Member__c> tms = [SELECT ID, Allocation_to_Team__c FROM Team_Member__c 
                                     WHERE Contact_Resource__c =:tm.Contact_Resource__c];  
                                       
            Integer sum=0;
         
        for (Team_Member__c teamMem:tms){
            sum += Integer.valueOf(teamMem.Allocation_to_Team__c);
            if(sum < 100){
                tms1.add(teamMem);
            }
            else{
                tm.addError('Total allocation to all the Teams cant be more than 100%');
                break;
            }            
        }
    }
    }

}

Hi,

I have contact object with Team Member as child object.
The child object has a field --- allocation.
My requirement is sum of allocations cant exceed 100%. I tried a validation rule by doing a roll up summary and saving that in a field and then validating that it should throw error when this summary field is greater than 100. It's not working.

Alternatively, I wrote a trigger and that too is not working. Please help.

trigger TrigAllocToTeam on Team_Member__c (before insert, before update) {
    for(Team_Member__c tm:Trigger.new){
        //Contact con=[SELECT Id FROM Contact where Id=:tm.Contact_Resource__r.id];
        List <Team_Member__c> tms = [SELECT ID, Allocation_to_Team__c FROM Team_Member__c 
                                    WHERE Contact_Resource__r.id =:tm.Contact_Resource__r.id];
        Decimal sum=0;
        for (Team_Member__c teamMem:tms){
            sum = sum + teamMem.Allocation_to_Team__c;
            if(sum>100){
                tm.addError('More than 100%');
            }
            
        }
    }
}
Hi,
I have the contact object which has 2 fields-- job code and job grade.
I have another object job code where there are 2 fields job code and job grade.
When a user creates a contact and enters a job code, he should get the job grade populated automatically.
How can do this using a Map?
Thanks.
Hi,
I need a before Trigger on Contact that will update my Job grade field based on what value I enter for Job Code.
For e.g: If I create a contact with name : John Smith and Job Code =101, the trigger will search the Job Code Object with Job Code =101 and return the corresponding Job Grade for that --- And populate my Job Grade field on the Contact object.
Thanks.
Hi,

How do I add a Cancel or Continue button in a Flow -screen?

Thanks.
Hi,
I have a requirement where I need to create a flow screen based on the value selected from previous screen.
Example: In the country dropdown, I selected 'USA', and click next, it will take me to screen A. If I select 'India', I will go to screen B.

Thanks in advance
Hi All,

I was asked this Q in one of the interviews. Eliminate all duplicate values from a string. For Eg. I/P = 'THEMISSISSIPPI'
O/P = 'THEM' (all other values are truncated because they are duplicates)
Can you please help. Appreciate your response.

Thanks.
Hi,
I need to send email to the Opportunity owner with the list of Products (added in the Opportunity) when the Opportunity is Closed Won. I am unable to write the logic for iterating over the products.
Thanks.
Hi,
I have added opportunity as a lookup in contact. I want my description on contact to be updated with the related opportunity's stage name. My following code is not working. Please let me know where I went wrong:

trigger populateOppStage on Contact (before insert, before update) {
   Set<ID> opps = New Set<ID>();
    for (contact con:trigger.new){
        opps.add(con.opportunity__r.Id);
    }
    Map<Id, String> mapOppToStage = New Map<Id, String>();
    for(opportunity opp:[SELECT ID, stagename 
                      FROM opportunity WHERE ID IN:opps]){
        mapOppToStage.put(opp.id, opp.stagename);
    }

    for (contact c:trigger.new){
        if(mapOppToStage.containsKey(c.opportunity__r.Id)){
                c.Description= mapOppToStage.get(c.Opportunity__r.id);
        }
    }
}

Hi,
I have Contact object with Team Member as child object. The sum of all the allocations of Team Members under a certain contact cant exceed 100.  
This helper class is not working properly. Please advise:

 

public class TrigAllocToTeamHandler {
    public static void chkTeamAlloc(List<Team_Member__c> teamList){
        
        for(Team_Member__c tm:teamList){
        List <Team_Member__c> tms = [SELECT ID, Allocation_to_Team__c FROM Team_Member__c 
                                     WHERE Contact_Resource__c =:tm.Contact_Resource__c];  
                                       
            Integer sum=0;
         
        for (Team_Member__c teamMem:tms){
            sum += Integer.valueOf(teamMem.Allocation_to_Team__c);
            if(sum < 100){
                tms1.add(teamMem);
            }
            else{
                tm.addError('Total allocation to all the Teams cant be more than 100%');
                break;
            }            
        }
    }
    }

}

Hi,

I have contact object with Team Member as child object.
The child object has a field --- allocation.
My requirement is sum of allocations cant exceed 100%. I tried a validation rule by doing a roll up summary and saving that in a field and then validating that it should throw error when this summary field is greater than 100. It's not working.

Alternatively, I wrote a trigger and that too is not working. Please help.

trigger TrigAllocToTeam on Team_Member__c (before insert, before update) {
    for(Team_Member__c tm:Trigger.new){
        //Contact con=[SELECT Id FROM Contact where Id=:tm.Contact_Resource__r.id];
        List <Team_Member__c> tms = [SELECT ID, Allocation_to_Team__c FROM Team_Member__c 
                                    WHERE Contact_Resource__r.id =:tm.Contact_Resource__r.id];
        Decimal sum=0;
        for (Team_Member__c teamMem:tms){
            sum = sum + teamMem.Allocation_to_Team__c;
            if(sum>100){
                tm.addError('More than 100%');
            }
            
        }
    }
}
Hi,
I need a before Trigger on Contact that will update my Job grade field based on what value I enter for Job Code.
For e.g: If I create a contact with name : John Smith and Job Code =101, the trigger will search the Job Code Object with Job Code =101 and return the corresponding Job Grade for that --- And populate my Job Grade field on the Contact object.
Thanks.
Hi All,

I was asked this Q in one of the interviews. Eliminate all duplicate values from a string. For Eg. I/P = 'THEMISSISSIPPI'
O/P = 'THEM' (all other values are truncated because they are duplicates)
Can you please help. Appreciate your response.

Thanks.
Hi,
I need to send email to the Opportunity owner with the list of Products (added in the Opportunity) when the Opportunity is Closed Won. I am unable to write the logic for iterating over the products.
Thanks.