• Kunal Purohit 4
  • NEWBIE
  • 140 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 61
    Questions
  • 19
    Replies
Hello All,
There is a custom metadata with four fields AreaCode,ZipCode,State and TimeZone. Whenever these field values are inserted/updated, TimeZone value need to be update. How to achieve this fucntionality through configuration or Lightning Flows?
Please suggest.

Hello Folks,
There are two System Admin in my Dev Org. Whenever, I will create new Contact record, it must be assigned to another System Admin and Whenever Other System Admin will create Contact Record, it should be assigned to me. (Round Robin)

Here AssignedTo__c is a custom field with Lookup Relation data type(User).

 

Please suggest.

Hello Folks,
How to write Handler for below trigger.?

trigger SumAmountOpp on Opportunity (After Insert,After Update,After Delete, After Undelete) {
 List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
    if(Trigger.isInsert){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
			}
		}
    } 
    system.debug('setAccIds ==> '+setAccIds);
    if(Trigger.isUpdate){
         if(trigger.isAfter){
        for(Opportunity con : Trigger.new){ 
            if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId && con.Amount>10000.00){
               	setAccIds.add(con.AccountId);
                setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
            	}
            
			}        
        }
    }
    if(Trigger.isDelete){
        if(trigger.isAfter){
        for(Opportunity con : Trigger.old) { 
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
        	}
        }
    } 
    
    if(Trigger.isUndelete){
        if(trigger.isAfter){
        for(Opportunity con : Trigger.new) { 
            if(con.AccountId != null && con.Amount>10000.00){
            setAccIds.add(con.AccountId);
            	}
        	}
        }
    } 
    for(Account acc :[Select id,Total_Opportunity__c ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : setAccIds]){
			
        acc.Total_Opportunity__c = acc.Opportunities.size();
        acclist.add(acc);
        
    }
    if(acclist.size()>0){
        update accList;     
    }
    
}

Hello Folks, 

I am new to salesforce development. Attempting to write a test class for below code. Please suggest.
 

public class CountContactHandler {
    
    public static void ContactCheckBox(List<Contact> con) {
        
        Set<Id> setid = new Set<Id>();
        for(Contact c : con) {
            setid.add(c.AccountId);
        }
        
        List<Account> acc1 = [SELECT Id, Name From Account WHERE Id In :setid];
        
        for(Account a1 : acc1) {
            
        }
    }

}

Hello Community,

In my VF page, I want to show/Hide Custom setting Component based on User Login. Is it possible through Configuration or else It requires codig?

Marked text is a link that derives from custom setting. Please suggest solution.User-added image

Hi,
In my org, there are two objects Case and Project. Case object is having lookup relation with Project and Account Object. Now whenever, Case record is cretaed for particular Project, its asscoiated Account should get populated in case record. Plz help to write trigger for same.
public class StatusPublished implements database.Batchable<sobject>,Schedulable{

    public void execute(Schedulablecontext sc)
    {
         string cron='0 2 * * * ?*';
        StatusPublished sp =new StatusPublished();
        system.schedule('updatepaper', cron, sp);
      //database.executeBatch(sp);
    }
        public database.QueryLocator start(database.BatchableContext bc)
    {
        string query='select id,Name,Status__c from Research_Paper__c';
        return database.getQueryLocator(query);
    }
        public void execute(database.BatchableContext bc,list<Account> acc)
    {
        List<Research_Paper__c> rlist=new list<Research_Paper__c>();
        for(Research_Paper__c rp: rlist)
        {
            if(rp.Status__c=='Paper registration Complete')
            {
                rp.Status__c='Published';
                rlist.add(rp);
            }
        }
        update rlist;
    }
    
     public void finish(database.BatchableContext bc)
    {
 
    }

 
I am writing this trigger to prevent duplicate entry. But this trigger runs even at time of creating new record..How to resolve?
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId) && acmap.get(opp.AccountId).Opportunities!=null)
        {
        
           {
               if(opp.StageName=='Prospecting')
               {
                     (opp.AccountId).addError('Duplicate value');
               }
           }
        }
    }
}
Scenario for trigger is that, if Opportunity Object having record with field stageName=='Prospecting ' and Parent Account name with,lets say XYZ.,so another record with same field value and same parent should not get duplicated.. I have written below trigger but it is showing error.

 
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId))
        {
           if(acmap.get(opp.AccountId).StageName=='Prospecting')
           {
               (opp.AccountId).addError('Duplicate value');
           }
        }
    }
}
I want to remove prefix 'Mr.' from my Account object. I have tried through the BatchApex class. But still its not working.
public class BatchApex1 implements database.Batchable<Sobject> {
    public database.QueryLocator start(database.BatchableContext Bc)
    {
        string query='select id,name from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext Bc, list<Account> alist)
    {
        for(account a:alist)
        {
           a.name= a.Name.removeStart('Mr.');
        }
        
        update alist;
        system.debug(alist);
    }
     public void finish(database.BatchableContext Bc)
    {
        
    }

}
 
I have junction object "Author-Research Paper". This object has two master detail relationship with objects "Authors" and "Research Paper".
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it?