• Ketan Parab 7
  • NEWBIE
  • 25 Points
  • Member since 2019
  • Salesforce Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi  Everyone
I am beginner in salesforce so i am facing a issue in this scenario
So Please Help me out for this Scenario How to Do this?

When User Opens the records by default current user's should be selected in 'Name of the Employee ' Field is on Visualforce Page and One Custom Object and in Custom Object when i clicked a new button for a record then the visualforce page is opened so the field is created in Visualforce Page with name Name of the Employee and this field fetch the all users records so i want when a user login with our credentials and go to the Custom object and create a new record then the Name of the Employee field is auto populated with login Users name in Name of the Employee Field and this situation for all users.
Hi  Everyone
I am beginner in salesforce so i am facing a issue in this scenario
So Please Help me out for this Scenario How to Do this?

When User Opens the records by default current user's should be selected in 'Name of the Employee ' Field is on Visualforce Page and One Custom Object and in Custom Object when i clicked a new button for a record then the visualforce page is opened so the field is created in Visualforce Page with name Name of the Employee and this field fetch the all users records so i want when a user login with our credentials and go to the Custom object and create a new record then the Name of the Employee field is auto populated with login Users name in Name of the Employee Field and this situation for all users.
Hi,  

I need help.  I have successfully written a trigger (my first) which adds users in 3 fields as editors of a custom object record. Where I need help is if one or more of those users in those 3 fields change, I need the previous user to no longer have access to the record. 

For Example: 
VP Approver is John Smith -- Record is Saved -- John Smith is given RW access to the record --> VP Approve is changed to Mary Morton--> John Smith no longer has any access to the record and Mary Morton now has RW to the record. 

Here is my current code which is working fine to give VP Approver access, but it does not take the access away when the user is changed. Any help is much appreciated! 

trigger agreement_Sharing on Apttus__APTS_Agreement__c (after update) {

    // We only execute the trigger after a Agreement record has been inserted 
    // because we need the Id of the Agreement record to already exist.
    if(trigger.isUpdate){
        
     
    List<Apttus__APTS_Agreement__Share> sharesToDelete = [SELECT Id 
                                                FROM Apttus__APTS_Agreement__Share 
                                                WHERE ParentId IN :trigger.newMap.keyset() 
                                                AND RowCause = 'Requester Sharing'];
//if(!sharesToDelete.isEmpty()){
    //Database.Delete(sharesToDelete, false);
//} 
    // APTS_Agreement__Share is the "Share" table that was created when the
    // Organization Wide Default sharing setting was set to "Private".
    // Allocate storage for a list of APTS_Agreement__Share records.
    List<Apttus__APTS_Agreement__Share> agreementShares  = new List<Apttus__APTS_Agreement__Share>();
        
        

    // For each of the Agreement records being inserted, do the following:
    for(Apttus__APTS_Agreement__c agreement : trigger.new){

        // Create a new APTS_Agreement__Share record to be inserted in to the APTS_Agreement__Share table.
        Apttus__APTS_Agreement__Share agreementShare = new Apttus__APTS_Agreement__Share();
            
        // Populate the APTS_Agreement__Share record with the ID of the record to be shared.
        agreementShare.ParentId = agreement.Id;
            
        // Then, set the ID of user or group being granted access. In this case,
        // we’re setting the Id of the agreement that was specified by 
        // the User in the agreement__c lookup field on the Agreement record.  
        // (See Image 1 to review the Agreement object's schema.)
        agreementShare.UserOrGroupId = agreement.GP_APVL_C_Level__c;
        //agreementShare.UserOrGroupId = agreement.GP_APVL_Sr_Director__c;
        //agreementShare.UserOrGroupId = agreement.GP_APVL_VP__c;
        //agreementShare.UserOrGroupId = agreement.GP_APVL_Additional__c;
       
        
        // Specify that the agreement should have edit access for 
        // this particular Agreement record.
        agreementShare.AccessLevel = 'edit';
            
        // Specify that the reason the agreement can edit the record is 
        // because he’s the agreement.
        // (agreement_Sharing__c is the Apex Sharing Reason that we defined earlier.)
        agreementShare.RowCause = Schema.Apttus__APTS_Agreement__Share.RowCause.Requester_Sharing__c;
            
        // Add the new Share record to the list of new Share records.
        agreementShares.add(agreementShare);
    }
        
    for(Apttus__APTS_Agreement__c agreement : trigger.new){

        Apttus__APTS_Agreement__Share agreementShare = new Apttus__APTS_Agreement__Share();
        agreementShare.ParentId = agreement.Id;
        agreementShare.UserOrGroupId = agreement.GP_APVL_Sr_Director__c;
        agreementShare.AccessLevel = 'edit';
        agreementShare.RowCause = Schema.Apttus__APTS_Agreement__Share.RowCause.Requester_Sharing__c;
        agreementShares.add(agreementShare);
    }
        
    for(Apttus__APTS_Agreement__c agreement : trigger.new){

        Apttus__APTS_Agreement__Share agreementShare = new Apttus__APTS_Agreement__Share();
        agreementShare.ParentId = agreement.Id;
        agreementShare.UserOrGroupId = agreement.GP_APVL_VP__c;
        agreementShare.AccessLevel = 'edit';
        agreementShare.RowCause = Schema.Apttus__APTS_Agreement__Share.RowCause.Requester_Sharing__c;
        agreementShares.add(agreementShare);
    } 
        
    for(Apttus__APTS_Agreement__c agreement : trigger.new){

        Apttus__APTS_Agreement__Share agreementShare = new Apttus__APTS_Agreement__Share();
        agreementShare.ParentId = agreement.Id;
        agreementShare.UserOrGroupId = agreement.GP_APVL_Additional__c;
        agreementShare.AccessLevel = 'edit';
        agreementShare.RowCause = Schema.Apttus__APTS_Agreement__Share.RowCause.Requester_Sharing__c;
        agreementShares.add(agreementShare);
    }
    // Insert all of the newly created Share records and capture save result 
    Database.SaveResult[] agreementShareInsertResult = Database.insert(agreementShares,false);
        
    // Error handling code omitted for readability.
    }
}