• SambitNayak
  • NEWBIE
  • 125 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 34
    Questions
  • 30
    Replies

Hi,

I'm writing a test class to check that I can change the status field of one of my objects successfully.
When I anonymously create the record with status ='New' and then change the status='Scheduled', I'm not facing any issues.

But when I'm using the exact same code in a Test Class, I'm facing the following issue:

 

EXCEPTION_THROWN [34]|System.DmlException: Update failed. First exception on row 0 with id 08p76000000sxxxxx; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Cannot change status from New to Scheduled: [Status]


Any advice is really appreciated. Thanks

Hi,
 
I want all my users to land on a particular page (a custom Home page). Although I have declared this page as my default Home page, the user lands on the page where he/she logged off from.
 
Any advice would be really helpful.
Thanks.

Hi,

I have a requirement where a field of the parent object changes everytime the user enters a NOTE.
I wrote a trigger on ContentDocumentLink (everytime a ContentDocumentLink record is created, the parent record's field changes) and it's working fine. However my Test Class is not allowing me to create 200 ContentDocumentLink records. Please review the code below and help if you have ever experienced such issues.
It's exceeding the governor limits:

Please note: CA.Id is my parent object (I have already inserted it in my earlier part of the code)

 

 

        for(Integer a=0;a<200;a++){
        Blob beforeblob=Blob.valueOf('Unit Test Attachment Body');
        ContentVersion cVersion = new ContentVersion(ContentLocation = 'S', PathOnClient = 'testPath', Title = 'testTitle’+a,
                                                    VersionData = beforeblob);
        contVerToInsert.add(cVersion);
        }
Insert contVerToInsert;
        
        for (ContentVersion cv:contVerToInsert){
    mapIndexToContVer.put(Integer.valueOf(cv.Title.remove('testTitle')),cv.Id);
}

        
        for(Integer j=0;j<200;j++){
                   ContentDocumentLink CDL = New ContentDocumentLink(LinkedEntityId=CA.Id, ShareType = 'V',
                                                              ContentDocumentId=mapIndexToContVer.get(j));

            notesToInsert.add(CDL);
        }

        Test.startTest();
        Insert notesToInsert;
        Test.stopTest();         
        
}



 

Hi,

I have added an LWC action button on one of my objects. The LWC is opening a screen and allowing users to enter few details and then the user clicks Save. It's creating a child record and automatically links it to the Parent record from which the user clicked the LWC action button.

How do I write a Test Class -- How do I mention in my Test Class that the LWC button is clicked and the assertEquals is returning all the correct values?
Hi,

I have a requirement where I need to update a field automatically after 15 days of since a note is created for that record. Can I achieve that using "After Trigger"?
Please advise.
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'm writing a test class to check that I can change the status field of one of my objects successfully.
When I anonymously create the record with status ='New' and then change the status='Scheduled', I'm not facing any issues.

But when I'm using the exact same code in a Test Class, I'm facing the following issue:

 

EXCEPTION_THROWN [34]|System.DmlException: Update failed. First exception on row 0 with id 08p76000000sxxxxx; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Cannot change status from New to Scheduled: [Status]


Any advice is really appreciated. Thanks

Hi,

I have a requirement where a field of the parent object changes everytime the user enters a NOTE.
I wrote a trigger on ContentDocumentLink (everytime a ContentDocumentLink record is created, the parent record's field changes) and it's working fine. However my Test Class is not allowing me to create 200 ContentDocumentLink records. Please review the code below and help if you have ever experienced such issues.
It's exceeding the governor limits:

Please note: CA.Id is my parent object (I have already inserted it in my earlier part of the code)

 

 

        for(Integer a=0;a<200;a++){
        Blob beforeblob=Blob.valueOf('Unit Test Attachment Body');
        ContentVersion cVersion = new ContentVersion(ContentLocation = 'S', PathOnClient = 'testPath', Title = 'testTitle’+a,
                                                    VersionData = beforeblob);
        contVerToInsert.add(cVersion);
        }
Insert contVerToInsert;
        
        for (ContentVersion cv:contVerToInsert){
    mapIndexToContVer.put(Integer.valueOf(cv.Title.remove('testTitle')),cv.Id);
}

        
        for(Integer j=0;j<200;j++){
                   ContentDocumentLink CDL = New ContentDocumentLink(LinkedEntityId=CA.Id, ShareType = 'V',
                                                              ContentDocumentId=mapIndexToContVer.get(j));

            notesToInsert.add(CDL);
        }

        Test.startTest();
        Insert notesToInsert;
        Test.stopTest();         
        
}



 

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');
    }
    }

}
}