• SambitNayak
  • NEWBIE
  • 110 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 29
    Questions
  • 26
    Replies
Hi All,

I want to navigate to a Lightning App Builder Page from my LWC. I dont want to hardcode my URL.
I'm using NavigationMixin but not sure how to pass the API name of my Page.
Any help is appreciated.

Thanks
Hi,
I have a requirement where the user clicks on a button and is navigated to an application.
I have created a function in my JS controller by creating an URL using the following text+ Application ID, but it's not working. Please let me know if you have any suggestions. How do I build my application URL when I know my application ID?

launchApp(){
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes:{
url : '/lightning/app/c__' + this.applicationMetadataToshow.Application_ID__c
}
});
}

Hi,
I need to create a Home Page where I should have 3 icons (mentioning 3 applications)--- Upon clicking, these icons should take me to respective Applications. Only those users who have access to the applications, can see the respective icons.For eg: Mr. Abc has access to Marketing application, and he can see this Marketing icon when he logs in.

Is there a way to find out programatically -- which user has access to which object (maybe at profile level or by Permission sets)

 

Thanks.

Hi,

I'm new to LWC.
How do I change the button color and size of a lightning-button? It's taking the default from "Variant".

Alternatively, can I use anything else (like icon)?

Any help in this regard is really appreciated.
Hi,
Is there an easy way to invoke an application from a Lighning Page?
For e.g: On the Home page, there should be 2 icons (or buttons) where the user can just click and get the Sales application or the Service Application launched.
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 a requirement where the user clicks on a button and is navigated to an application.
I have created a function in my JS controller by creating an URL using the following text+ Application ID, but it's not working. Please let me know if you have any suggestions. How do I build my application URL when I know my application ID?

launchApp(){
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes:{
url : '/lightning/app/c__' + this.applicationMetadataToshow.Application_ID__c
}
});
}
Hi,
Is there an easy way to invoke an application from a Lighning Page?
For e.g: On the Home page, there should be 2 icons (or buttons) where the user can just click and get the Sales application or the Service Application launched.
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;
            }            
        }
    }
    }

}