• Karan_Jain
  • NEWBIE
  • 45 Points
  • Member since 2021
  • Associate Software Developer


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
public class VisitTriggerHandler {
           
    public static void sTime (List<visit__c> newVisits){
        
        set<id> physicianId = new set<id>();
        
        for (visit__c vis : newVisits) {
            physicianId.add(vis.OwnerId);
        }
        
        List<Visit__c> oldVisits = [
            SELECT id,Name, ownerid, Visitation__c, Timespan__c, Visitation_End__c
            FROM visit__c
            Where ownerid in : physicianId
        ];
        
       
        
        
        for (visit__c vis : oldVisits) {
            for(visit__c visit : newVisits){
                
                if(visit.Visitation__c == vis.Visitation__c){
                    visit.Visitation__c.addError('The date you have selected is not available');
                    
                }
            }
                
        }
  • July 22, 2022
  • Like
  • 0
how to find the & replace the sting in the custom metadata in the salesforce??????????????
public class VisitTriggerHandler {
           
    public static void sTime (List<visit__c> newVisits){
        
        set<id> physicianId = new set<id>();
        
        for (visit__c vis : newVisits) {
            physicianId.add(vis.OwnerId);
        }
        
        List<Visit__c> oldVisits = [
            SELECT id,Name, ownerid, Visitation__c, Timespan__c, Visitation_End__c
            FROM visit__c
            Where ownerid in : physicianId
        ];
        
       
        
        
        for (visit__c vis : oldVisits) {
            for(visit__c visit : newVisits){
                
                if(visit.Visitation__c == vis.Visitation__c){
                    visit.Visitation__c.addError('The date you have selected is not available');
                    
                }
            }
                
        }
  • July 22, 2022
  • Like
  • 0
Hello,

Is it possible to have a contact trigger in which it clears a formula value if another field stores the same value? the logic is if the phone number is the same as the custom formula field phone number then the custom formula field will clear its value and turns blank.

Thnx!
Hey guys trying to get comfortable with the Salesforce CLI, and went to deploy my code changes to my Dev Org but I keep getting the following error message. I checked out the link that they listed, but couldn't seem to figure out what issue was. I modified the JSON with the folder name that I'm trying to deploy, but still had no luck. 
 
Error deploying or retrieving source: The file or directory that you tried to deploy or retrieve isn't in a package directory that's specified in your sfdx-project.json file. Add this location to your "packageDirectories" value, or deploy or retrieve a different file or directory. For details about sfdx-project.json, see: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm

 
Hi, how can I view all my validation rules on one screen as opposed to having to go through each object?
Hi All,

I want to display number of contacts associated with an account using triggers.

for this I had created a lookup field like noofcontacts__c in account  object. and Wrote code as

trigger numberofcontacts on contact(after insert, after update, after delete) {
    Map<Id, List<Contact>> AcctContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();   
    List<schema.Account> AcctList = new List<schema.Account>();
    List<schema.Contact> ConList = new List<schema.Contact>();
   
    if(trigger.isInsert || trigger.isUPdate) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId)){
                AcctIds.add(Con.AccountId); 
            }  
        } 
    }
   
    if(trigger.isDelete) {
        for(Contact Con : trigger.Old) {
            AcctIds.add(Con.AccountId);    
        } 
    }          
   
    if(AcctIds.size() > 0){
        ConList = [SELECT Id, AccountId FROM Contact WHERE AccountId IN : AcctIds];
       
        for(Contact Con : ConList) {
            if(!AcctContactList.containsKey(Con.AccountId)){
                AcctContactList.put(Con.AccountId, new List<Contact>());
            }
            AcctContactList.get(Con.AccountId).add(Con);     
        }                          
      
           
        AcctList = [SELECT noofContacts__c FROM Account WHERE Id IN : AcctIds];
        for(Account Acc : AcctList) {
            List<schema.Contact> ContList = new List<schema.Contact>();
            ContList = AcctContactList.get(Acc.Id);
            Acc.Number_of_Contacts__c = ContList.size();
        }   
       
      
        update AcctList;   
    }

}
 I am   getting an error as "Variable doesnot exist:id".

Kindly support and suggest.

Thanks