• CKR
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 11
    Questions
  • 8
    Replies
Hi All,
My current trigger avoids updating Status__c field on accounts from 'Open' to 'close' when both Account's status__c and its related Opportunities status__C is 'Open', Now,How can i use the same condition to avoid those accounts from being deleted(Before delete even which throws custom error message).
 my current condition in trigger is working for both before update and before delete events,but the before delete event in the trigger is not allowing me to delete any other records, those even didn't met the condition and i am seeing the follow error message instead i want to populate the custom error message.
  Help will be appreciated. 

User-added image
trigger AvoidStatusUpdateOnAcct on Account(before update,before delete) 
{  Set<Id> acctIdSet = new Set<Id>();   
    for (Account acct : Trigger.new)      
    {
        acctIdSet.Add(acct.Id);              
    }
    
    Map<Id, Account> acctMap = new Map<Id, Account>([SELECT Id,Name,Status__c, (SELECT Id FROM Opportunities WHERE Status__c = 'Open') FROM Account WHERE Id in :acctIdSet]);   
    for (Account acct : Trigger.new)
    {   List<Opportunity> oppList = acctMap.get(acct.Id).Opportunities;       
        if (acct.Status__c == 'Close' && oppList != null && oppList.size() >= 1)
        {
           acct.addError('Account ' + acct.Name + ' still has open opportunities.'); 
        }
    
    }
 }


Thanks
CKR    
  • June 22, 2016
  • Like
  • 0
Hi All,
Learnt a bit about how to avoid recursive triggers, now i wonder, Why static boolean variable ? why not just boolean variable to use inorder to avoid recursive triggers?
  • June 22, 2016
  • Like
  • 0
Hi All,
Where does exactly the sales process starts like the initial point of the sales process and the end point of  sales process,my guess is from Leads to Opportunities,but i was told, not correct.
  • June 21, 2016
  • Like
  • 0
Hi All,
How to write a trigger while a cusotm field (Picklist)  status__C on account is changing from Open to Processing,its related contacts have to be fetched and the checkbox field "Yes" on related contacts have to be ''checked'' i.e as "True". i tried using trigger.new/Old , which did not worked at all and my code looks terrible, so i am not posting here. actually my reason behind this question is to know the perfect use case that makes me sense of the importance of trigger.Newmap, trigger.oldmap and trigger,Isexecuting.
Help will be appreciated.
Thanks
CKR
  • June 16, 2016
  • Like
  • 0
Hi All,
How to analyze or measure the performance of a visualforce page, to make sure that its performance is efficient enough, i mean what are the principles to be followed, for instance, in terms of page loading time while diaplaying records or performing DML operations on huge amount of data on a particular visualforce page.i have seen lot of references aout best practices of VF page but but could not find much info about my above question.

Thanks
CKR
  • June 16, 2016
  • Like
  • 0
Hi All,
How to solve the issue,if i have a requirement to use more than 100 Soql queries,wondering if there is any possible way out there.

Thanks
CKR
  • June 15, 2016
  • Like
  • 0
Hi All,
How to make different sets of picklist values available to different users under a profile but whithout creating record types,i was told by an interviewer that it is possible.wondering how??
 
  • June 15, 2016
  • Like
  • 0
Hi All
Here is my trigger to limit a user to create only 10 cases in a month,it is half working accordingly, but i would like to put the logic in the apex class which is currently in the trigger, more over my trigger is restricting the users to create cases when they exceeded specified limit but i am seeing the first line of error 'Invalid Date' which is unexpected along with the custom error message that i have written in the trigger.
User-added image
 
Trigger LimitNoOfCases on case(Before insert){
    If (Trigger.IsInsert){
    Integer MonthNumber = Date.Today().Month();
    Integer YearNumber = Date.Today().Year();
    Integer MaxCases = Integer.valueof(System.Label.MaxCasesLimit);//configured maximum number of cases per user by creating Custom label.
    Id Xuser = UserInfo.Getuserid();
    User Usr = [select name from user where id=:userinfo.getuserid()];
    List<Case> LstCase = [select id,CreatedById,CreatedDate from case where CALENDAR_YEAR(CreatedDate) =:YearNumber and CALENDAR_MONTH(CreatedDate)=:monthnumber and CreatedById=:UserInfo.GetUserId()];
 
    If (Lstcase.Size()>=MaxCases)         
   {   
      Trigger.New[0].addError('Dear user you have exceeded the maximum number of cases allowed this month.');
   }  
     
  }
}

 
  • June 15, 2016
  • Like
  • 0
Hi EveryOne,
I am a newbee, here is my trigger which is not working as expected,I would like to make this work on both before Insert and before update events,the requirement is whenever an account is either going to be created or updated with its Test_Amount__c  field's value = or > 100000,
then the Rating field should have the value as 'Hot' on both Before insert and Before upadate event.
 
trigger InUpAccts on Account (before insert,before update) {
    
    if (trigger.isbefore && trigger.Isupdate)
    {     
        for (Account A : Trigger.New)
        {  List <Account> Aclist = New List <Account> ();
            System.debug('------------------------>'+Trigger.New);
          
            If (A.Name !=null && A.Test_Amount__c == 100000)
             {   
                System.debug('------------------------>'+A.Test_Amount__c);
                Account Acct = New Account();
                //Acct.Name =
                Acct.Rating = 'Hot';
                Aclist.add(Acct);
             }
            If (Aclist.size()>0)
              {   
                System.debug('------------------------>'+Aclist.size());
                Insert Aclist;
                System.debug('------------------------>'+Aclist);
              } 
            else If (A.Name !=null && A.Test_Amount__c == 100)
            {
            Update Aclist;
            }    
        }
    }
}

 
  • June 04, 2016
  • Like
  • 0
Hi EveryOne,

I am a newbee, trying to cover the triggers topic, i am facing a prolem to finishing off writting the following trigger,Could someone help me with this,
I have a master Object Client__c and its child project__c,
1) On after Insert event a child record has to be created and i am successfull till here,
Now the problem is i have similar fields in both master and child objects Start_Date__c and End_Date__c (Date fields), i am unable to pop the same values of master record fields in the child record on after insert event.
2) On after Update The requirement is similar to after insert but the only difference is this has to be happend only on update event 
 Please refere to the If statement in the code,i am trying to make both events of this trigger work only on that particular condition.
 
trigger AutoProjects on Client__c (After insert,After update){
 
    
   if(Trigger.isafter){
   if (trigger.Isinsert){
    List <Project__c> NewProjs= new List <Project__c> ();
        for(client__c Clnt:trigger.new)
        { if (Clnt.High_Priority__c == true){
            Project__c p=new project__c();
            p.Name=Clnt.Name;
       //     p.Start_date__c='Clnt.Start_date__c' ;   // Field value has to be same as Start_date__c of master record
    //    p.End_Date__c = 'Clnt.End_Date__c' ;     // Field value has to be same as End_Date__c of master record
            p.Client_Type__c='Silver';
            p.Location__c = Clnt.Location__c;
            p.Client__c= clnt.Id;                  //Master-detail relationship name
            NewProjs.add(p);
        }
        }
        if (NewProjs.size()>0){
        Insert NewProjs;    
        }
       
      }  
    }
    
    if(Trigger.isafter){
   if (trigger.IsUpdate){
    List <Project__c> NewProjs= new List <Project__c> ();
        for(client__c Clnt:trigger.new)
        { if (Clnt.High_Priority__c == true){
            Project__c p=new project__c();
            p.Name=Clnt.Name;
       //     p.Start_date__c='Clnt.Start_date__c' ;   // Field value has to be same as Start_date__c of master record
    //    p.End_Date__c = 'Clnt.End_Date__c' ;     // Field value has to be same as End_Date__c of master record
            p.Client_Type__c='Silver';
            p.Location__c = Clnt.Location__c;
            p.Client__c= clnt.Id;                  //Master-detail relationship name
            NewProjs.add(p);
        }
        }
        if (NewProjs.size()>0){
        Update NewProjs;    
        }
       
      }  
    }
}

The Error Message that i am seeing on after update even:
User-added image
 
  • June 04, 2016
  • Like
  • 0
Hi,
could someone help me,how to write the trigger based on the following scenario,

for instance, i have a custom field called status (picklist with values 'open' 'Closed') on both Account and opportunity objects,
now if an account has 4 related opportunities with 2 of them with status as 'open' and other 2 as closed,lets say, if an account's status is 'open' along with any of its related opportutnities as 'open', then a custom error has to be thrown if any user try to change the status of the Account from Open to close.
  • June 01, 2016
  • Like
  • 0
Hi All,
My current trigger avoids updating Status__c field on accounts from 'Open' to 'close' when both Account's status__c and its related Opportunities status__C is 'Open', Now,How can i use the same condition to avoid those accounts from being deleted(Before delete even which throws custom error message).
 my current condition in trigger is working for both before update and before delete events,but the before delete event in the trigger is not allowing me to delete any other records, those even didn't met the condition and i am seeing the follow error message instead i want to populate the custom error message.
  Help will be appreciated. 

User-added image
trigger AvoidStatusUpdateOnAcct on Account(before update,before delete) 
{  Set<Id> acctIdSet = new Set<Id>();   
    for (Account acct : Trigger.new)      
    {
        acctIdSet.Add(acct.Id);              
    }
    
    Map<Id, Account> acctMap = new Map<Id, Account>([SELECT Id,Name,Status__c, (SELECT Id FROM Opportunities WHERE Status__c = 'Open') FROM Account WHERE Id in :acctIdSet]);   
    for (Account acct : Trigger.new)
    {   List<Opportunity> oppList = acctMap.get(acct.Id).Opportunities;       
        if (acct.Status__c == 'Close' && oppList != null && oppList.size() >= 1)
        {
           acct.addError('Account ' + acct.Name + ' still has open opportunities.'); 
        }
    
    }
 }


Thanks
CKR    
  • June 22, 2016
  • Like
  • 0
Please help me finding correct answers for the below questions. Explanation for the answers would be more helpful.

1) A developer creates an Apex helper class to handle complex trigger logic. How can the helper class warn users when the trigger exceeds DML governor limits?
 A) By using ApexMessage.Message() to display an error message after the number of DML statements is exceeded.
 B) By using Messaging.SendEmail() to conthtinue the transaction and send an alert to the user after the number DML statements is exceeded.
 C) By using PageReference.setRedirect() to redirect the user to a custom Visualforce page before the number DML statements is exceeded.
 D) By using Limits.getDMLRows() and then displaying an error message before the number of DML statements exceeded.
 
2) Where can debug log filter settings be set Choose 2 answers?
 A) The Filters link by the monitored user's name within the web UI.
 B) The Show more link on the debug log's record.
 C) On the monitored user's name.
 D) The Log Filters tab on a class or trigger detail page.
 
3) When can a developer use a custom Visualforce page in a Force.com application? Choose 2 answers
 A) To create components for dashboards and layouts.
 B) To deploy components between two organizations.
 C) To generate a PDF document with application data.
 D) To modify the page layout settings for a custom object.
 
4) What is an important consideration when developing in a multi-tenant environment?
 A) Polyglot persistence provides support for a global, multilingual user base in multiple orgs on multiple instances.
 B) Governor limits prevent tenants from impacting performance in multiple orgs on the same instance.
 C) Unique domain names take tile place of namespaces for code developed for multiple orgs on multiple instances.
 D) 
Org-wide data security determines whether other tenants can see data in multiple orgs on the same instance

 
Hi All
Here is my trigger to limit a user to create only 10 cases in a month,it is half working accordingly, but i would like to put the logic in the apex class which is currently in the trigger, more over my trigger is restricting the users to create cases when they exceeded specified limit but i am seeing the first line of error 'Invalid Date' which is unexpected along with the custom error message that i have written in the trigger.
User-added image
 
Trigger LimitNoOfCases on case(Before insert){
    If (Trigger.IsInsert){
    Integer MonthNumber = Date.Today().Month();
    Integer YearNumber = Date.Today().Year();
    Integer MaxCases = Integer.valueof(System.Label.MaxCasesLimit);//configured maximum number of cases per user by creating Custom label.
    Id Xuser = UserInfo.Getuserid();
    User Usr = [select name from user where id=:userinfo.getuserid()];
    List<Case> LstCase = [select id,CreatedById,CreatedDate from case where CALENDAR_YEAR(CreatedDate) =:YearNumber and CALENDAR_MONTH(CreatedDate)=:monthnumber and CreatedById=:UserInfo.GetUserId()];
 
    If (Lstcase.Size()>=MaxCases)         
   {   
      Trigger.New[0].addError('Dear user you have exceeded the maximum number of cases allowed this month.');
   }  
     
  }
}

 
  • June 15, 2016
  • Like
  • 0
Hi EveryOne,
I am a newbee, here is my trigger which is not working as expected,I would like to make this work on both before Insert and before update events,the requirement is whenever an account is either going to be created or updated with its Test_Amount__c  field's value = or > 100000,
then the Rating field should have the value as 'Hot' on both Before insert and Before upadate event.
 
trigger InUpAccts on Account (before insert,before update) {
    
    if (trigger.isbefore && trigger.Isupdate)
    {     
        for (Account A : Trigger.New)
        {  List <Account> Aclist = New List <Account> ();
            System.debug('------------------------>'+Trigger.New);
          
            If (A.Name !=null && A.Test_Amount__c == 100000)
             {   
                System.debug('------------------------>'+A.Test_Amount__c);
                Account Acct = New Account();
                //Acct.Name =
                Acct.Rating = 'Hot';
                Aclist.add(Acct);
             }
            If (Aclist.size()>0)
              {   
                System.debug('------------------------>'+Aclist.size());
                Insert Aclist;
                System.debug('------------------------>'+Aclist);
              } 
            else If (A.Name !=null && A.Test_Amount__c == 100)
            {
            Update Aclist;
            }    
        }
    }
}

 
  • June 04, 2016
  • Like
  • 0
Hi,
could someone help me,how to write the trigger based on the following scenario,

for instance, i have a custom field called status (picklist with values 'open' 'Closed') on both Account and opportunity objects,
now if an account has 4 related opportunities with 2 of them with status as 'open' and other 2 as closed,lets say, if an account's status is 'open' along with any of its related opportutnities as 'open', then a custom error has to be thrown if any user try to change the status of the Account from Open to close.
  • June 01, 2016
  • Like
  • 0
Please help me finding correct answers for the below questions. Explanation for the answers would be more helpful.

1) A developer creates an Apex helper class to handle complex trigger logic. How can the helper class warn users when the trigger exceeds DML governor limits?
 A) By using ApexMessage.Message() to display an error message after the number of DML statements is exceeded.
 B) By using Messaging.SendEmail() to conthtinue the transaction and send an alert to the user after the number DML statements is exceeded.
 C) By using PageReference.setRedirect() to redirect the user to a custom Visualforce page before the number DML statements is exceeded.
 D) By using Limits.getDMLRows() and then displaying an error message before the number of DML statements exceeded.
 
2) Where can debug log filter settings be set Choose 2 answers?
 A) The Filters link by the monitored user's name within the web UI.
 B) The Show more link on the debug log's record.
 C) On the monitored user's name.
 D) The Log Filters tab on a class or trigger detail page.
 
3) When can a developer use a custom Visualforce page in a Force.com application? Choose 2 answers
 A) To create components for dashboards and layouts.
 B) To deploy components between two organizations.
 C) To generate a PDF document with application data.
 D) To modify the page layout settings for a custom object.
 
4) What is an important consideration when developing in a multi-tenant environment?
 A) Polyglot persistence provides support for a global, multilingual user base in multiple orgs on multiple instances.
 B) Governor limits prevent tenants from impacting performance in multiple orgs on the same instance.
 C) Unique domain names take tile place of namespaces for code developed for multiple orgs on multiple instances.
 D) 
Org-wide data security determines whether other tenants can see data in multiple orgs on the same instance