• SambitNayak
  • NEWBIE
  • 90 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 24
    Replies
Hi,
I have a requirement to distribute the amount on Parent Account equally among all opportunities. The following code is throwing NULL pointer exception. Please help.


public static void distAmountEqually(List<Opportunity> oppList, map<Id,Opportunity>oldmap, boolean isInsert, boolean isUpdate){
        Set<Id> oppAccIds = New Set<Id>();
        Map<Id,List<opportunity>> mapAccToOpps = New Map<Id,List<opportunity>>();
        Integer noOfOpps = 0;
        List<Opportunity> oppsToUpdt = New List<Opportunity>();

        for(Opportunity opp:oppList){
            oppAccIds.add(opp.accountId);
        }
        
        for(Account acc: [SELECT AnnualRevenue ,(SELECT Distributed_Amount__c FROM Opportunities) 
                          FROM Account WHERE Id IN :oppAccIds]){
            
            if(!mapAccToOpps.containsKey(acc.Id)){ 
                mapAccToOpps.put(acc.Id, new List<opportunity>());                
            }
            mapAccToOpps.get(acc.Id).addall(acc.opportunities);
        }
        
        for(Opportunity op:oppList){
            if(mapAccToOpps.containsKey(op.accountId)){
                 noOfOpps= op.account.Opportunities.size();

                 for(Opportunity opy:mapAccToOpps.get(op.accountId)){
                    opy.Distributed_Amount__c = op.Account.AnnualRevenue / noOfOpps;
                }
            }
        }
    
    }
}

Hi,
I need to add a description on my Account every time an Opportunity's stage is changed.
I tried the following and getting NULL pointer exception. Please help:

 

public class opportunityTriggerHandler {
    public static void oppStgChangeDetails(List<Opportunity> oppList, map<Id,Opportunity>oldmap, boolean isInsert, boolean isUpdate){
        List<Account> accsToUpdate = New List<Account>();

for(Opportunity opp:oppList){
            if(isInsert || (isUpdate && opp.stageName <> oldmap.get(opp.Id).stageName)){
                opp.Account.Description = opp.Account.Description + 'Prev Stage: ' +oldmap.get(opp.Id).stageName 
                    + 'New Stage: '+opp.StageName;
                accsToUpdate.add(opp.Account);
            }
        }
        update accsToUpdate;
    }
}

Hi,
I have a requirement to count the number of candidates looking upto a Test Center object. The field "No of Candidates" on the Test Center object should calculate the number of candidates associated.
I wrote an After trigger but it's not updating the field:

trigger candidateTrigger on Candidate__c (after insert, after update, after delete) {
    candidateTriggerHandler.calcNoOfCandidates(Trigger.isDelete ? Trigger.old : Trigger.new);
}

//Handler class
public class candidateTriggerHandler {
    
    public static void calcNoOfCandidates(List<Candidate__c> candList){
        Set<ID> TestCenters= New Set<ID>();
        for(Candidate__c can:candList){
            if(can.Test_Center__r.ID != NULL){
            TestCenters.add(can.Test_Center__r.ID);
            }
        }
Map<Id,List<Candidate__c>> mapTestCntrToCand = New Map<Id,List<Candidate__c>>();
        
        for(Test_Center__c tc:[SELECT ID, No_of_Candidates__c , (SELECT Id FROM Candidates__r) 
                               FROM Test_Center__c WHERE Id IN:TestCenters]){
            mapTestCntrToCand.put(tc.Id, tc.Candidates__r);
        }
        
        for(Candidate__c can:candList){
            if(mapTestCntrToCand.containsKey(can.Test_Center__r.ID)){
                Integer noOfCands=0;
                for(Candidate__c c:mapTestCntrToCand.get(can.Test_Center__r.ID)){
                    noOfCands++;
                    system.debug('no of cndts inside for loop: '+ noOfCands);
                }
                can.Test_Center__r.No_of_Candidates__c = noOfCands;
                system.debug('no of cndts outside for loop: '+ noOfCands);
            }
        }
    }
 

Hi,
I have a requirement where i need to update a field on Account object everytime a related case is closed.
The Field "Closed Cases" is a number field on Account object. Everytime, I close a case, this field should be incremented by 1.
I wrote a trigger but it's showing NULL Pointer Exception. 
Please let me know if you see any issues here:

 

public class caseTriggerHandler {

    public static void autoFillNoOfContacts(List<Case> caseList, map<id, Case> oldCase){
        Set<ID> AccIDs= New Set<ID>();
        List<Account> accsToUpdate = New List<Account>();
        
        for (Case cs:caseList){
            if(cs.status=='closed' && oldCase.get(cs.Id).status<>'closed'){
            AccIDs.add(cs.AccountId);
        }
        }
                       
        Decimal noOfCases= 0;
        for(Account acc: [SELECT ID, Closed_Cases__c, (SELECT Id,Status FROM Cases) FROM Account WHERE Id IN:AccIDs]){
            noOfCases+=noOfCases;
            acc.Closed_Cases__c+=noOfCases;
            accsToUpdate.add(acc);
        }
        update accsToUpdate;
    }
}

I have a contact and I want to find all the Opportunities related to this contact's parent Account. Is there any single SOQL query to achieve this?
Hi,
I have a custom object and 2 users from same profile are seeing different behaviours. Although the CRED access on the profile is CRE, the 1st user is able to edit it while the 2nd one cant.
There are no validation rules or Triggers on the object. No Permission set is assigned to both users.
The 2nd user sees the following validation error. I am unable to create debug logs as the profile doesn't have access to 'SetUp' (when I create a Permission Set to grant access to 'SetUp', it opens up the visiblity to all data and hence the user doesnt face the issue anymore). Please help me if you have encountered similar issues.
User-added image

Hi All,
I have a managed package object and want to include it as one of the tabs. Unfortunately, I am not able to find the object when I go to Profiles>> System Admin>> Custom Objects. I also tried visiting App Manager>>My Application >> Navigation Items.
Hi,
I have 2 objects which are completely unrelated to each other. Howerver, they both are related to the Contact object. How do I find the records from Contact which are common to both the objects.
Hi,
I have a requirement to create a new account(if the entered account doesn't exist already) every time a contact is created/edited from ETL (The ETL profile user) 

    public static void createAutoVendor(List<Contact> contList, boolean isInsert, boolean isUpdate, Map<Id, Contact> oldContacts){
        Set<Id> existingAccs = New Set<Id>();
        Set<String> existingAccNames = New Set<String>();
        List<Account> newAccs = New List<Account>();
        Map<String, Id> mapAccToCont = New Map<String, Id>();
        Id createdBy=[SELECT Id FROM User WHERE Name  = 'ETL User'].id;
                
        //Select all the existing Accounts and add them to the Set of Accounts
        for (Account acc:[SELECT Id, Name FROM Account]){
            existingAccs.add(acc.id);
            existingAccNames.add(acc.Name);
        }
        for (Contact con:contList){
            if(con.Vendor__c <> null){  //Vendor__c is the name of the account in ETL

                if(((isInsert && con.CreatedById==createdBy) ||
                   (isUpdate && con.LastModifiedById==createdBy 
                    && con.Vendor__c<>oldContacts.get(con.Id).Vendor__c))
                  && (!existingAccNames.contains(con.Vendor__c))){
                       Account Acc = New Account(name=con.Vendor__c, Type='Vendor'); //Create a new Account if it's not existing already
                       newAccs.add(Acc);

                   }
                insert newAccs;

            }            
        }
        for (Account acc:newAccs){
            mapAccToCont.put(acc.Name, acc.Id);

        }
        for (Contact con:contList){
            if(mapAccToCont.containsKey(con.Vendor__c)){
                con.AccountId=mapAccToCont.get(con.Vendor__c);

            }
        }        
    }

This code is working when I am running from the "Execute Anonymous Window" as an Admin. But failing from ETL with following error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactTrigger: execution of BeforeInsert

Any help in this regard is really appreciated.
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,
I have a requirement to distribute the amount on Parent Account equally among all opportunities. The following code is throwing NULL pointer exception. Please help.


public static void distAmountEqually(List<Opportunity> oppList, map<Id,Opportunity>oldmap, boolean isInsert, boolean isUpdate){
        Set<Id> oppAccIds = New Set<Id>();
        Map<Id,List<opportunity>> mapAccToOpps = New Map<Id,List<opportunity>>();
        Integer noOfOpps = 0;
        List<Opportunity> oppsToUpdt = New List<Opportunity>();

        for(Opportunity opp:oppList){
            oppAccIds.add(opp.accountId);
        }
        
        for(Account acc: [SELECT AnnualRevenue ,(SELECT Distributed_Amount__c FROM Opportunities) 
                          FROM Account WHERE Id IN :oppAccIds]){
            
            if(!mapAccToOpps.containsKey(acc.Id)){ 
                mapAccToOpps.put(acc.Id, new List<opportunity>());                
            }
            mapAccToOpps.get(acc.Id).addall(acc.opportunities);
        }
        
        for(Opportunity op:oppList){
            if(mapAccToOpps.containsKey(op.accountId)){
                 noOfOpps= op.account.Opportunities.size();

                 for(Opportunity opy:mapAccToOpps.get(op.accountId)){
                    opy.Distributed_Amount__c = op.Account.AnnualRevenue / noOfOpps;
                }
            }
        }
    
    }
}

Hi,
I need to add a description on my Account every time an Opportunity's stage is changed.
I tried the following and getting NULL pointer exception. Please help:

 

public class opportunityTriggerHandler {
    public static void oppStgChangeDetails(List<Opportunity> oppList, map<Id,Opportunity>oldmap, boolean isInsert, boolean isUpdate){
        List<Account> accsToUpdate = New List<Account>();

for(Opportunity opp:oppList){
            if(isInsert || (isUpdate && opp.stageName <> oldmap.get(opp.Id).stageName)){
                opp.Account.Description = opp.Account.Description + 'Prev Stage: ' +oldmap.get(opp.Id).stageName 
                    + 'New Stage: '+opp.StageName;
                accsToUpdate.add(opp.Account);
            }
        }
        update accsToUpdate;
    }
}

Hi,
I have a requirement to count the number of candidates looking upto a Test Center object. The field "No of Candidates" on the Test Center object should calculate the number of candidates associated.
I wrote an After trigger but it's not updating the field:

trigger candidateTrigger on Candidate__c (after insert, after update, after delete) {
    candidateTriggerHandler.calcNoOfCandidates(Trigger.isDelete ? Trigger.old : Trigger.new);
}

//Handler class
public class candidateTriggerHandler {
    
    public static void calcNoOfCandidates(List<Candidate__c> candList){
        Set<ID> TestCenters= New Set<ID>();
        for(Candidate__c can:candList){
            if(can.Test_Center__r.ID != NULL){
            TestCenters.add(can.Test_Center__r.ID);
            }
        }
Map<Id,List<Candidate__c>> mapTestCntrToCand = New Map<Id,List<Candidate__c>>();
        
        for(Test_Center__c tc:[SELECT ID, No_of_Candidates__c , (SELECT Id FROM Candidates__r) 
                               FROM Test_Center__c WHERE Id IN:TestCenters]){
            mapTestCntrToCand.put(tc.Id, tc.Candidates__r);
        }
        
        for(Candidate__c can:candList){
            if(mapTestCntrToCand.containsKey(can.Test_Center__r.ID)){
                Integer noOfCands=0;
                for(Candidate__c c:mapTestCntrToCand.get(can.Test_Center__r.ID)){
                    noOfCands++;
                    system.debug('no of cndts inside for loop: '+ noOfCands);
                }
                can.Test_Center__r.No_of_Candidates__c = noOfCands;
                system.debug('no of cndts outside for loop: '+ noOfCands);
            }
        }
    }
 

Hi,
I have a requirement where i need to update a field on Account object everytime a related case is closed.
The Field "Closed Cases" is a number field on Account object. Everytime, I close a case, this field should be incremented by 1.
I wrote a trigger but it's showing NULL Pointer Exception. 
Please let me know if you see any issues here:

 

public class caseTriggerHandler {

    public static void autoFillNoOfContacts(List<Case> caseList, map<id, Case> oldCase){
        Set<ID> AccIDs= New Set<ID>();
        List<Account> accsToUpdate = New List<Account>();
        
        for (Case cs:caseList){
            if(cs.status=='closed' && oldCase.get(cs.Id).status<>'closed'){
            AccIDs.add(cs.AccountId);
        }
        }
                       
        Decimal noOfCases= 0;
        for(Account acc: [SELECT ID, Closed_Cases__c, (SELECT Id,Status FROM Cases) FROM Account WHERE Id IN:AccIDs]){
            noOfCases+=noOfCases;
            acc.Closed_Cases__c+=noOfCases;
            accsToUpdate.add(acc);
        }
        update accsToUpdate;
    }
}

I have a contact and I want to find all the Opportunities related to this contact's parent Account. Is there any single SOQL query to achieve this?
Hi,
I have a custom object and 2 users from same profile are seeing different behaviours. Although the CRED access on the profile is CRE, the 1st user is able to edit it while the 2nd one cant.
There are no validation rules or Triggers on the object. No Permission set is assigned to both users.
The 2nd user sees the following validation error. I am unable to create debug logs as the profile doesn't have access to 'SetUp' (when I create a Permission Set to grant access to 'SetUp', it opens up the visiblity to all data and hence the user doesnt face the issue anymore). Please help me if you have encountered similar issues.
User-added image

Hi All,
I have a managed package object and want to include it as one of the tabs. Unfortunately, I am not able to find the object when I go to Profiles>> System Admin>> Custom Objects. I also tried visiting App Manager>>My Application >> Navigation Items.
Hi,
I have a requirement to create a new account(if the entered account doesn't exist already) every time a contact is created/edited from ETL (The ETL profile user) 

    public static void createAutoVendor(List<Contact> contList, boolean isInsert, boolean isUpdate, Map<Id, Contact> oldContacts){
        Set<Id> existingAccs = New Set<Id>();
        Set<String> existingAccNames = New Set<String>();
        List<Account> newAccs = New List<Account>();
        Map<String, Id> mapAccToCont = New Map<String, Id>();
        Id createdBy=[SELECT Id FROM User WHERE Name  = 'ETL User'].id;
                
        //Select all the existing Accounts and add them to the Set of Accounts
        for (Account acc:[SELECT Id, Name FROM Account]){
            existingAccs.add(acc.id);
            existingAccNames.add(acc.Name);
        }
        for (Contact con:contList){
            if(con.Vendor__c <> null){  //Vendor__c is the name of the account in ETL

                if(((isInsert && con.CreatedById==createdBy) ||
                   (isUpdate && con.LastModifiedById==createdBy 
                    && con.Vendor__c<>oldContacts.get(con.Id).Vendor__c))
                  && (!existingAccNames.contains(con.Vendor__c))){
                       Account Acc = New Account(name=con.Vendor__c, Type='Vendor'); //Create a new Account if it's not existing already
                       newAccs.add(Acc);

                   }
                insert newAccs;

            }            
        }
        for (Account acc:newAccs){
            mapAccToCont.put(acc.Name, acc.Id);

        }
        for (Contact con:contList){
            if(mapAccToCont.containsKey(con.Vendor__c)){
                con.AccountId=mapAccToCont.get(con.Vendor__c);

            }
        }        
    }

This code is working when I am running from the "Execute Anonymous Window" as an Admin. But failing from ETL with following error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactTrigger: execution of BeforeInsert

Any help in this regard is really appreciated.
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.