• Mohit Sharma 37
  • NEWBIE
  • 90 Points
  • Member since 2015

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 11
    Replies
I wrote the following class that I intend to use as a helper class:

public class RoleUtils {

    public static ID userId {get;set;} //variable for this user id
    public static ID userRoleId {get;set;} //variable for this user role id
    public static Set<ID> userSubs {get;set;} //variable for all subordinates to this user in role hierarchy
    public static Set<ID> userSubRoles {get;set;}
    public static Set<ID> userPar {get;set;} //variable for all parents to this user in role hierarchy
    public static Set<ID> usergroup {get;set;}

    public static void getIds(){
        usergroup = new Set<ID>();
        userId = UserInfo.getUserId();
        usergroup.add(userId);
        userRoleId = UserInfo.getUserRoleId();
        userSubRoles = new Set<ID>();
        
        for(UserRole subRole :[select Id from UserRole where ParentRoleId = :userRoleId AND ParentRoleID != null])
        {
            userSubRoles.add(subRole.Id);
        }
        for(User subuser :[SELECT ID, UserRoleId FROM User WHERE UserRoleId IN :userSubRoles])
        {
            usergroup.add(subuser.Id);
        }
        
        system.debug('userId '+userId);
        system.debug('userRoleId '+userRoleId);
        system.debug('userSubRoles '+userSubRoles);
        system.debug('usergroup '+usergroup);
    }
}

In another class I have:

        Date currentDate = System.today();
        Date minusonemonth = currentDate.addMonths(-1);
        Date plusoneyear = currentDate.addYears(1);
        Date plusthreemonths = currentDate.addDays(90);
        RoleUtils roleUtil = new RoleUtils();

        getCon = [SELECT RecordTypeId, Contract_Number__c, Owned_by_me__c, Account__c, Account__r.Name, Id, Name, Utility__c, Contract_Nom_Group__c, Supplier__c, Consultant__c, Contract_End_Date__c, Pro_forma_Annual_Margin__c, Annual_Contract_Volume__c
                FROM NG_Contract__c
                WHERE Contract_End_Date__c >= :minusonemonth
                AND Contract_End_Date__c <= :plusthreemonths
                ORDER BY Contract_End_Date__c ASC
                LIMIT 10];

I would like to add a filter to my list to choose records owned by one of the users in my usergroup variable from my helper class. How do I do this?
Hello Developers!

I have this trigger on opportunity which allows only $500 opportunity amount per day per user. Now Trigger seem to be working fine. But however, I have a question.
Since the upcoming record's Id is not availble in Trigger.New then why is it works at line 18? Wouldn't the opp.Id is null at that line?
Trigger FiveHundred_Dollars_Opp_Amount_Limit on Opportunity(Before Insert, Before Update, After UnDelete){
     
     If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
         
         For(Opportunity opp : Trigger.New){
             
             If(Opp.Amount > 500){
                 Opp.addError('Opportunitys Amount Can not be greater than $500 per day.');
             }
             else If(Opp.Amount == null){
                 // Let it go.
             }
             
             else If(opp.Amount != null){
                 
                 List<Opportunity> FetchingCurrentUsersTodaysOpps = [Select Id, Amount
                                                                             FROM Opportunity
                                                                                 WHERE Id != :Opp.Id
                                                                                 AND   CreatedDate = Today
                                                                                 AND   Amount != null
                                                                                 AND   OwnerId =:Opp.OwnerId];
                 Double SummingAmount = Opp.Amount;
                 If(!FetchingCurrentUsersTodaysOpps.IsEmpty()){
                     
                     For(Opportunity EveryOpp : FetchingCurrentUsersTodaysOpps){
                         SummingAmount += EveryOpp.Amount;
                     }
                 If(SummingAmount > 500){
                     Opp.addError('You have reached the miximum limit of $500 opportunity Amount Per Day.');
                 }
                 }
             }
         }
     }
}

Thank You!
Capital One has loaned us their Salesforce team to help our Non-Profit move our 2000+ contacts from Gift Works to Salesforce. The question they have is if GW contacts are listed as Mr. & Mrs. Smith (not John Smith and Sally Smith) How do they load that to Salesforce? Do they go straight to household? What is the work around?  
I wrote the following class that I intend to use as a helper class:

public class RoleUtils {

    public static ID userId {get;set;} //variable for this user id
    public static ID userRoleId {get;set;} //variable for this user role id
    public static Set<ID> userSubs {get;set;} //variable for all subordinates to this user in role hierarchy
    public static Set<ID> userSubRoles {get;set;}
    public static Set<ID> userPar {get;set;} //variable for all parents to this user in role hierarchy
    public static Set<ID> usergroup {get;set;}

    public static void getIds(){
        usergroup = new Set<ID>();
        userId = UserInfo.getUserId();
        usergroup.add(userId);
        userRoleId = UserInfo.getUserRoleId();
        userSubRoles = new Set<ID>();
        
        for(UserRole subRole :[select Id from UserRole where ParentRoleId = :userRoleId AND ParentRoleID != null])
        {
            userSubRoles.add(subRole.Id);
        }
        for(User subuser :[SELECT ID, UserRoleId FROM User WHERE UserRoleId IN :userSubRoles])
        {
            usergroup.add(subuser.Id);
        }
        
        system.debug('userId '+userId);
        system.debug('userRoleId '+userRoleId);
        system.debug('userSubRoles '+userSubRoles);
        system.debug('usergroup '+usergroup);
    }
}

In another class I have:

        Date currentDate = System.today();
        Date minusonemonth = currentDate.addMonths(-1);
        Date plusoneyear = currentDate.addYears(1);
        Date plusthreemonths = currentDate.addDays(90);
        RoleUtils roleUtil = new RoleUtils();

        getCon = [SELECT RecordTypeId, Contract_Number__c, Owned_by_me__c, Account__c, Account__r.Name, Id, Name, Utility__c, Contract_Nom_Group__c, Supplier__c, Consultant__c, Contract_End_Date__c, Pro_forma_Annual_Margin__c, Annual_Contract_Volume__c
                FROM NG_Contract__c
                WHERE Contract_End_Date__c >= :minusonemonth
                AND Contract_End_Date__c <= :plusthreemonths
                ORDER BY Contract_End_Date__c ASC
                LIMIT 10];

I would like to add a filter to my list to choose records owned by one of the users in my usergroup variable from my helper class. How do I do this?
I am trying to insert a new Case record in salesforce, so I created the REST in Java for that.
In both the APEX developer console and a inserting method in REST I use the field AccountID, but
in Salesforce website I have to choose string-typed name of a company for the field Account Name.
I also checked all possible fields for the case object in developer console and I didn't see AccountName field. However, when I used a specific ID (picked a random one from developer console) for AccountID in REST, the newly created case record acquired the Account Name associated with that Account ID. Is there a way to use Account Name direclty from REST instead of using AccountID?
Hello All,

We have a vfpage that is displayed to our site users. This page displays various rich text fields but when there is an image in the rich text field it is not being shown to the site user. The profile has access to the fields but the images are returning the 'Image not available' error. This really seems to be specific to our site profile and I am wondering if anyone knows if this is a limitation of Sites?
I have never made a trigger before and I am not sure where to start for this task. I have two custom objects. object A and object B. When the picklist value of a field in custom object B is selected it needs to change the checkbox field in object A to true. Does anyone know how to do this? I have tried to do this through a workflow and process builder but it cannot be done.
Hello Developers!

I have this trigger on opportunity which allows only $500 opportunity amount per day per user. Now Trigger seem to be working fine. But however, I have a question.
Since the upcoming record's Id is not availble in Trigger.New then why is it works at line 18? Wouldn't the opp.Id is null at that line?
Trigger FiveHundred_Dollars_Opp_Amount_Limit on Opportunity(Before Insert, Before Update, After UnDelete){
     
     If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
         
         For(Opportunity opp : Trigger.New){
             
             If(Opp.Amount > 500){
                 Opp.addError('Opportunitys Amount Can not be greater than $500 per day.');
             }
             else If(Opp.Amount == null){
                 // Let it go.
             }
             
             else If(opp.Amount != null){
                 
                 List<Opportunity> FetchingCurrentUsersTodaysOpps = [Select Id, Amount
                                                                             FROM Opportunity
                                                                                 WHERE Id != :Opp.Id
                                                                                 AND   CreatedDate = Today
                                                                                 AND   Amount != null
                                                                                 AND   OwnerId =:Opp.OwnerId];
                 Double SummingAmount = Opp.Amount;
                 If(!FetchingCurrentUsersTodaysOpps.IsEmpty()){
                     
                     For(Opportunity EveryOpp : FetchingCurrentUsersTodaysOpps){
                         SummingAmount += EveryOpp.Amount;
                     }
                 If(SummingAmount > 500){
                     Opp.addError('You have reached the miximum limit of $500 opportunity Amount Per Day.');
                 }
                 }
             }
         }
     }
}

Thank You!
Hi

Im using a URL hack for a lookup field to pre-populate the value when creating new record, unfortunately value being showed in the field is "_HL_ENCODED_/_HL_   _HL__blank_HL_" expected output should be the Name of a record.

Thanks

I created a new custom field that is a replacement of an existing one.  The existing field is referenced in an Apex Class.  When I attempt to update the Apex Class with the new field API name I receive the following error:

 

Error: Compile Error: alias is too long, maximum of 25 characters

 

Has anyone seen this error before?  Any suggestions on how to correct it?

 

Thanks

 

  • November 15, 2013
  • Like
  • 0