• SambitNayak
  • NEWBIE
  • 50 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 12
    Replies
Hi,

I have a requirement where the user wants to see the value of an auto-generated number appended with the name in the same name field.
Example:
User is creating a record and entering value 'ABC' in the name field. Upon saving, the user should see the value 'X-000 ABC' in the name field (X-000 is an auto number in this object).
I used a Record-Triggered Flow but unfortunately it's working only on update (not when the user creates a record).
Any advise or help is highly appreciated.

Hi,
I have a Custom Object - Vendor_Contract__c.
Another custon object Work Allocation. It is looking up to object Vendor_Contract (Vendor Contract to Work Allocation is 1 to many relationship). I should not be able to delete a Vendor Contract when there is any related Work Allocation present. 
I dont know where my code is breaking. I am not getting the desired error.

Please have a look into my code and any advice is appreciated

public class LabContractTriggerHandler {
public static void checkWorkAllocation(List<Vendor_Contract__c> LabContractList, boolean isDelete){
    
    Set<Id> listLabCont = New Set<ID>();
    for (Vendor_Contract__c ven: [SELECT ID, (SELECT ID FROM Work_Allocations__r) FROM Vendor_Contract__c WHERE Id IN :LabContractList]){
            if(ven.Work_Allocations__r.size()>0){
                listLabCont.add(ven.Id);
            }
        }
    for(Vendor_Contract__c venCont:LabContractList){
            if(listLabCont.contains(venCont.Id) && isDelete){
                venCont.addError('You cant delete a Labor Contract with Work Allocations. Please delete the Work Allocations before deleting the Labor Contract');
    }
    }

}
}

Hi,
I have a custom object: Team Member. It is looking up to another custom object Vendor_Contract (Vendor Contract to Team Member is 1 to many relationship). My trigger accurately restricts users to create mulitple Team Members with total allocations exceeding above 100 % for a particular Vendor Contract. For example Vendor 1 has 3 Team Members. The allocation sum of these 3 team members cant exceed 100%.
I have written the following Test class which is unable to provide coverage. Not sure how to handle this. Any help will be definitely helpful.

 @isTest static void TestCreateNewLabContAllocMoreThan100(){
        List<Team_Member__c> tms= New List<Team_Member__c>();

        Vendor_Contract__c ven= New Vendor_Contract__c(Name='Test Vendor');
        Insert ven;

        Insert team;
        for(Integer i=0; i<200; i++){
            Team_Member__c tm= New Team_Member__c(Vendor_Contract__c=ven.id, Allocation_to_Team__c=1);
            tms.add(tm);
        }
         
        String message;
        Test.startTest();
        try{
            insert tms;
        }catch(Exception e){
            message = e.getMessage();
        }
        Test.stopTest();   
        List<Vendor_Contract__c> venCont = [SELECT Id, (SELECT Id, Allocation_to_Team__c FROM Team_Members__r) FROM Vendor_Contract__c WHERE Id =:ven.Id];
        for(Team_Member__c tm:venCont.Team_Members__r){
            system.assertEquals(tm.Allocation_to_Team__c, 1);            
        }
        
    } 
Hi,
I have a custom object Vendor Contract. Another Custom object Team Member with a look up to Vendor Contract. So there is a 1 to many relationship between Vendor Contract and Team Member.

My following query is not executing and I'm getting the error:
Query:
List<Vendor_Contract__c> contractList = [SELECT Id, (SELECT Id, Allocation_to_Team__c FROM Team_Members__r) FROM Vendor_Contract__c WHERE Id IN :listLabCont];
                          
Error:

Didn't understand relationship 'Team_Members__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Hi,
I have a custom object "Team Member" which is related to Contact through lookup. The Team Member object has a field called "Allocation to team". My requirement is -- The sum of Allocations of the teams for a particular contact should not exceed 100. 
I have the following code. But, it's breaking everytime the allocation sum reaches 100 (and it's not allowing me to change after that). 
Please help.
-----------------My Code is below-------------------
public class TeamMemberTriggerHandler {
    public static void checkTeamAllocation(List<Team_Member__c> TeamList, Map<Id, Team_Member__c> oldTeamList, boolean isInsert, boolean isUpdate){
        Set<ID> listContacts = New Set<ID>();
        for (Team_Member__c tm: TeamList){
            listContacts.add(tm.Contact_Resource__c);
        }
        Map<Id,List<Team_Member__c>> mapContToTmMem = New Map<Id,List<Team_Member__c>>();
        if(!listContacts.isEmpty()){

            List<contact> conList = [SELECT Id, (SELECT Id, Allocation_to_Team__c FROM Team_Members__r) FROM contact WHERE Id IN :listContacts];
            for(Contact con:conList){
                mapContToTmMem.put(con.Id, con.Team_Members__r);
            }
        }
        if(!mapContToTmMem.isEmpty()){
            Decimal AllocationSum=0;
            for(Team_Member__c tm:TeamList){
                if(mapContToTmMem.containsKey(tm.Contact_Resource__c)){                   
                    for(Team_Member__c teamMem:mapContToTmMem.get(tm.Contact_Resource__c)){
                        AllocationSum =AllocationSum + teamMem.Allocation_to_Team__c;
                if(AllocationSum > 100){
                    tm.addError('The total allocations for a particular ContactResource can\'t be more than 100%');
                    }
                        } 

                    }
                } 

            }
        }
    }
    
}
 
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 a requirement where the user wants to see the value of an auto-generated number appended with the name in the same name field.
Example:
User is creating a record and entering value 'ABC' in the name field. Upon saving, the user should see the value 'X-000 ABC' in the name field (X-000 is an auto number in this object).
I used a Record-Triggered Flow but unfortunately it's working only on update (not when the user creates a record).
Any advise or help is highly appreciated.

Hi,
I have a Custom Object - Vendor_Contract__c.
Another custon object Work Allocation. It is looking up to object Vendor_Contract (Vendor Contract to Work Allocation is 1 to many relationship). I should not be able to delete a Vendor Contract when there is any related Work Allocation present. 
I dont know where my code is breaking. I am not getting the desired error.

Please have a look into my code and any advice is appreciated

public class LabContractTriggerHandler {
public static void checkWorkAllocation(List<Vendor_Contract__c> LabContractList, boolean isDelete){
    
    Set<Id> listLabCont = New Set<ID>();
    for (Vendor_Contract__c ven: [SELECT ID, (SELECT ID FROM Work_Allocations__r) FROM Vendor_Contract__c WHERE Id IN :LabContractList]){
            if(ven.Work_Allocations__r.size()>0){
                listLabCont.add(ven.Id);
            }
        }
    for(Vendor_Contract__c venCont:LabContractList){
            if(listLabCont.contains(venCont.Id) && isDelete){
                venCont.addError('You cant delete a Labor Contract with Work Allocations. Please delete the Work Allocations before deleting the Labor Contract');
    }
    }

}
}

Hi,
I have a custom object: Team Member. It is looking up to another custom object Vendor_Contract (Vendor Contract to Team Member is 1 to many relationship). My trigger accurately restricts users to create mulitple Team Members with total allocations exceeding above 100 % for a particular Vendor Contract. For example Vendor 1 has 3 Team Members. The allocation sum of these 3 team members cant exceed 100%.
I have written the following Test class which is unable to provide coverage. Not sure how to handle this. Any help will be definitely helpful.

 @isTest static void TestCreateNewLabContAllocMoreThan100(){
        List<Team_Member__c> tms= New List<Team_Member__c>();

        Vendor_Contract__c ven= New Vendor_Contract__c(Name='Test Vendor');
        Insert ven;

        Insert team;
        for(Integer i=0; i<200; i++){
            Team_Member__c tm= New Team_Member__c(Vendor_Contract__c=ven.id, Allocation_to_Team__c=1);
            tms.add(tm);
        }
         
        String message;
        Test.startTest();
        try{
            insert tms;
        }catch(Exception e){
            message = e.getMessage();
        }
        Test.stopTest();   
        List<Vendor_Contract__c> venCont = [SELECT Id, (SELECT Id, Allocation_to_Team__c FROM Team_Members__r) FROM Vendor_Contract__c WHERE Id =:ven.Id];
        for(Team_Member__c tm:venCont.Team_Members__r){
            system.assertEquals(tm.Allocation_to_Team__c, 1);            
        }
        
    } 
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.