• Ilene Jones
  • NEWBIE
  • 20 Points
  • Member since 2014
  • Developer
  • Florida Virtual School


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 5
    Questions
  • 10
    Replies

I just finished writing and testing my apex and visual force page in Spring '15.  I decided to use the @testSetup method since I have a few different ways that I wanted to test this code.  I used the standard syntax, and all was well in Spring '15 - 85% code coverage, not perfect but I can come back to refine later for those extra few percentage points - Time to DEPLOY to production!  Not so much.  

Validation fails in production (Winter '15) with the error: Unknown annotation: testSetup ... 

I tried switching the API version to a lower version (droped it to 30) and the annotation error persists.

I followed the instructions here to no avail: 
https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_annotation_testsetup.htm|StartTopic=Content%2Fapex_classes_annotation_testsetup.htm|SkinName=webhelp

My test class is structured properly and has no errors in my sandbox.  Is this just a bug in the Spring '15 beta?

@isTest
public class ClubMembershipControllerTest {

    //
    // First, set up our dataset that all other test methods will use
    // 
    @testSetup static void setup() {
        // my inserts are here

    }
    //
    // This is a negative test to make sure that the student application cannot be duplicated.
    // This test is specifically to test the trigger code.
    //     
    public static testMethod void studentClubApplicationTest() {
        // first test case that uses the above inserts.
    }    
}
 


 

Currently I have a trigger which auto-follows specific groups in our organization when a new user is brought onboard.  The auto-follow trigger feature works great!  However, we have quite a few groups we would like these users to follow, based on various departments, which means that the user will get emails for each of the groups they are added to.  I would like to turn off email notifications during this process.

To do this, I found Database.DMLOptions.triggerUserEmail.  This seems to be exactly what I am looking for, however the sending of th email persists.  Below is the short function which is called by the trigger.  As you can see, I tried adding the options to both the cand ChatterGroupMember object and to the database.insert.  Using only one of these email header option sections also continues to send the email - as if it is being completely ignored.

Any assistance would be greatly appreciated.

public static void AddToGroups(Set<Id> userIds)
    {
        List<User> users = [select Id, Username from User where Id in :userIds];             
        Set<Id> updateUsers = new Set<Id>();
        // set up the groups that the user should be added to
        /*  All Users should be changed to the correct name of the group containing the department list */
        List<CollaborationGroup> chatterGroups=[select id, Name from CollaborationGroup where name like :ANNOUNCEMENT_GROUPS];

        // Start a new list that we can add new members to for the single update call.
        List<CollaborationGroupMember> chatterGroupMembers=new List<CollaborationGroupMember>();
              
        // loop the users - do not recheck for the flag, it may have already been updated!
        for (User user : users) {
            // loop the groups
            for (CollaborationGroup chatterGroup : chatterGroups) {
                // if is not already member, add the user to the group
                if(IsMember(chatterGroup.id, user.Id) == false) {

                    CollaborationGroupMember cand =
                        new CollaborationGroupMember(CollaborationGroupId=chatterGroup.id, MemberId = user.Id);

                    // Do not send an email to the users about the groups they're joining.
                    Database.DMLOptions dlo = new Database.DMLOptions();
                    dlo.EmailHeader.triggerAutoResponseEmail = false;
                    dlo.EmailHeader.triggerUserEmail = false;
                   
                    // Set the email options on the user we're working with
                    cand.setOptions(dlo);

                    // Now add the user to the group list
                    chatterGroupMembers.add(cand);

                    // why did I do this?
                    updateUsers.add(user.Id);
                }
            }
        }
        // Only run the insert if needed
        System.Debug(chatterGroupMembers);

        // Do not send an email to the users about the groups they're joining.
        Database.DMLOptions dlo = new Database.DMLOptions();
        dlo.EmailHeader.triggerAutoResponseEmail = false;
        dlo.EmailHeader.triggerUserEmail = false;
       
        Database.insert( chatterGroupMembers, dlo);    
    }


We are using SDocs with images hosted in Box due to image size constraints.  We are having an issue where the PDF renders VERY quickly, however the images which are hosted on Box do not have time to render before the PDF creation is complete.  Is there a way to slow down the PDF creation process to ensure that the images are rendered prior to the PDF finalization?

This was working for about 2 months, however we're back to this issue after Summer '14 release.  We did find a whitelist issue that was resolved, so the images are not broken, however they also do not show up.

We've updated to SDocs Winter '15 in our sandbox (we do not have a Salesforce Winter '15 instance this time), however that does not solve the issue.  In addition, we're using direct links (non-redirected) to ensure that the images are loaded as quickly as possible.

In the trigger below, I am attempting to update a custom object called Instructors__c when a user changes.  I'm looking for specific criteria, if they've become inactive, and if they're in a specific department, otherwise I move on.  The issue however is that my update is throwing a MIXED_DML_OPERATION error.  I found references to the @future option, however I need to pass an object to test against with at least 4 elements, the User id, EmployeeNumber, Department and isActive flag.

I did try putting this into a separate function with @future using this as a reference: http://salesforce-evershine-knowledge.blogspot.com/2012/09/unsupported-parameter-type-in-future.html.  That solution had it's own set of issues and errors, namely passing in the information via the objects.  

Any thoughts would be greatly appreciated.

// Run this only on update
    if(Trigger.isUpdate == true) {
        
        // When we deactivate a user, check to see if they are in instructor department
        // if they are, take their exit date and add it to the instructor object
        // and set them to inactive on the instructor object as well.        

    // Department name that instructors belong to
   String department='Instruction';

        //MASS ERROR MESSAGE
        String ErrorMsg = '';

        List<Instructor__c> instructorsToUpdate = new List<Instructor__c>();
        // Loop through each user, in case there is more than one user passed in
        for(User theUser : trigger.new) {            

            // If we have an active user, and that user happens to be in instruction
            if(theUser.isActive == false && theUser.Department  == department) {

                try {
                    // Get the instructor from the instructor and update their record
                    Instructor__c theInstructor = [SELECT Id, TeacherActive__c, Employee_Departure_Date__c FROM Instructor__c WHERE TeacherEmployeeID__c = :theUser.EmployeeNumber LIMIT 1];
                    // Make sure we have an object before trying to work with or update it.
                    if(theInstructor != null) {
                        theInstructor.TeacherActive__c = false;
                        theInstructor.Employee_Departure_Date__c = theUser.Exit_Date__c;
                        // Optimization
                        instructorsToUpdate.add(theInstructor);
                        ErrorMsg = ErrorMsg + 'Instructor: '+theInstructor.Name+', departure: '+theInstructor.Employee_Departure_Date__c+'\n';
                    }
                } catch(System.QueryException e) {
                    System.debug('Failed to find Instructor: ' + e);
                    ErrorMsg += 'Croaked while attempting find Instructor in Instructors__c using employee number: '+ theUser.EmployeeNumber + '<br/>Error: '+ e + '<br /><br/>'; 
                }
            }
        }
        // Do the update on the list, not the individual for batch/optimization
        update instructorsToUpdate;


Error Message text: 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger User_AI caused an unexpected exception, contact your administrator: User_AI: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0UR0000003jSkcMAE; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Instructor__c, original object: User: []: Trigger.User_AI: line 42, column 1

This likely needs to be put in the support forum instead, but I thought I would ask if anyone else is seeing this in the developer console on CS2?  I only see this on our sandbox, NOT on our production instance.  It acts as if 1) it has lost the connection or 2) has multiple connections / windows open, which it does not.

Full error message:

Failed to create createContainerMember for containerId=1dc500000004Cq7AAE: This container member belongs to a container that currently has an unfinished save request with deploymentId=1drR0000000Bs5I. You may not modify any members in this container until it completes.: Metadata Container ID

This likely needs to be put in the support forum instead, but I thought I would ask if anyone else is seeing this in the developer console on CS2?  I only see this on our sandbox, NOT on our production instance.  It acts as if 1) it has lost the connection or 2) has multiple connections / windows open, which it does not.

Full error message:

Failed to create createContainerMember for containerId=1dc500000004Cq7AAE: This container member belongs to a container that currently has an unfinished save request with deploymentId=1drR0000000Bs5I. You may not modify any members in this container until it completes.: Metadata Container ID

Hi

I need to create a document set in sharepoint online from salesforce after creating a new account record, how to achieve this.

I have gone through the Files connect and lightning connect both are having only the read the columns and files from sharepoint but the write operation from salesforce to sharepoint is not possible.

Is there any other way to create/update a sharepoint custom column from salesforce

Thanks
Dinesh

I just finished writing and testing my apex and visual force page in Spring '15.  I decided to use the @testSetup method since I have a few different ways that I wanted to test this code.  I used the standard syntax, and all was well in Spring '15 - 85% code coverage, not perfect but I can come back to refine later for those extra few percentage points - Time to DEPLOY to production!  Not so much.  

Validation fails in production (Winter '15) with the error: Unknown annotation: testSetup ... 

I tried switching the API version to a lower version (droped it to 30) and the annotation error persists.

I followed the instructions here to no avail: 
https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_annotation_testsetup.htm|StartTopic=Content%2Fapex_classes_annotation_testsetup.htm|SkinName=webhelp

My test class is structured properly and has no errors in my sandbox.  Is this just a bug in the Spring '15 beta?

@isTest
public class ClubMembershipControllerTest {

    //
    // First, set up our dataset that all other test methods will use
    // 
    @testSetup static void setup() {
        // my inserts are here

    }
    //
    // This is a negative test to make sure that the student application cannot be duplicated.
    // This test is specifically to test the trigger code.
    //     
    public static testMethod void studentClubApplicationTest() {
        // first test case that uses the above inserts.
    }    
}
 


 

Currently I have a trigger which auto-follows specific groups in our organization when a new user is brought onboard.  The auto-follow trigger feature works great!  However, we have quite a few groups we would like these users to follow, based on various departments, which means that the user will get emails for each of the groups they are added to.  I would like to turn off email notifications during this process.

To do this, I found Database.DMLOptions.triggerUserEmail.  This seems to be exactly what I am looking for, however the sending of th email persists.  Below is the short function which is called by the trigger.  As you can see, I tried adding the options to both the cand ChatterGroupMember object and to the database.insert.  Using only one of these email header option sections also continues to send the email - as if it is being completely ignored.

Any assistance would be greatly appreciated.

public static void AddToGroups(Set<Id> userIds)
    {
        List<User> users = [select Id, Username from User where Id in :userIds];             
        Set<Id> updateUsers = new Set<Id>();
        // set up the groups that the user should be added to
        /*  All Users should be changed to the correct name of the group containing the department list */
        List<CollaborationGroup> chatterGroups=[select id, Name from CollaborationGroup where name like :ANNOUNCEMENT_GROUPS];

        // Start a new list that we can add new members to for the single update call.
        List<CollaborationGroupMember> chatterGroupMembers=new List<CollaborationGroupMember>();
              
        // loop the users - do not recheck for the flag, it may have already been updated!
        for (User user : users) {
            // loop the groups
            for (CollaborationGroup chatterGroup : chatterGroups) {
                // if is not already member, add the user to the group
                if(IsMember(chatterGroup.id, user.Id) == false) {

                    CollaborationGroupMember cand =
                        new CollaborationGroupMember(CollaborationGroupId=chatterGroup.id, MemberId = user.Id);

                    // Do not send an email to the users about the groups they're joining.
                    Database.DMLOptions dlo = new Database.DMLOptions();
                    dlo.EmailHeader.triggerAutoResponseEmail = false;
                    dlo.EmailHeader.triggerUserEmail = false;
                   
                    // Set the email options on the user we're working with
                    cand.setOptions(dlo);

                    // Now add the user to the group list
                    chatterGroupMembers.add(cand);

                    // why did I do this?
                    updateUsers.add(user.Id);
                }
            }
        }
        // Only run the insert if needed
        System.Debug(chatterGroupMembers);

        // Do not send an email to the users about the groups they're joining.
        Database.DMLOptions dlo = new Database.DMLOptions();
        dlo.EmailHeader.triggerAutoResponseEmail = false;
        dlo.EmailHeader.triggerUserEmail = false;
       
        Database.insert( chatterGroupMembers, dlo);    
    }


We are using SDocs with images hosted in Box due to image size constraints.  We are having an issue where the PDF renders VERY quickly, however the images which are hosted on Box do not have time to render before the PDF creation is complete.  Is there a way to slow down the PDF creation process to ensure that the images are rendered prior to the PDF finalization?

This was working for about 2 months, however we're back to this issue after Summer '14 release.  We did find a whitelist issue that was resolved, so the images are not broken, however they also do not show up.

We've updated to SDocs Winter '15 in our sandbox (we do not have a Salesforce Winter '15 instance this time), however that does not solve the issue.  In addition, we're using direct links (non-redirected) to ensure that the images are loaded as quickly as possible.

In the trigger below, I am attempting to update a custom object called Instructors__c when a user changes.  I'm looking for specific criteria, if they've become inactive, and if they're in a specific department, otherwise I move on.  The issue however is that my update is throwing a MIXED_DML_OPERATION error.  I found references to the @future option, however I need to pass an object to test against with at least 4 elements, the User id, EmployeeNumber, Department and isActive flag.

I did try putting this into a separate function with @future using this as a reference: http://salesforce-evershine-knowledge.blogspot.com/2012/09/unsupported-parameter-type-in-future.html.  That solution had it's own set of issues and errors, namely passing in the information via the objects.  

Any thoughts would be greatly appreciated.

// Run this only on update
    if(Trigger.isUpdate == true) {
        
        // When we deactivate a user, check to see if they are in instructor department
        // if they are, take their exit date and add it to the instructor object
        // and set them to inactive on the instructor object as well.        

    // Department name that instructors belong to
   String department='Instruction';

        //MASS ERROR MESSAGE
        String ErrorMsg = '';

        List<Instructor__c> instructorsToUpdate = new List<Instructor__c>();
        // Loop through each user, in case there is more than one user passed in
        for(User theUser : trigger.new) {            

            // If we have an active user, and that user happens to be in instruction
            if(theUser.isActive == false && theUser.Department  == department) {

                try {
                    // Get the instructor from the instructor and update their record
                    Instructor__c theInstructor = [SELECT Id, TeacherActive__c, Employee_Departure_Date__c FROM Instructor__c WHERE TeacherEmployeeID__c = :theUser.EmployeeNumber LIMIT 1];
                    // Make sure we have an object before trying to work with or update it.
                    if(theInstructor != null) {
                        theInstructor.TeacherActive__c = false;
                        theInstructor.Employee_Departure_Date__c = theUser.Exit_Date__c;
                        // Optimization
                        instructorsToUpdate.add(theInstructor);
                        ErrorMsg = ErrorMsg + 'Instructor: '+theInstructor.Name+', departure: '+theInstructor.Employee_Departure_Date__c+'\n';
                    }
                } catch(System.QueryException e) {
                    System.debug('Failed to find Instructor: ' + e);
                    ErrorMsg += 'Croaked while attempting find Instructor in Instructors__c using employee number: '+ theUser.EmployeeNumber + '<br/>Error: '+ e + '<br /><br/>'; 
                }
            }
        }
        // Do the update on the list, not the individual for batch/optimization
        update instructorsToUpdate;


Error Message text: 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger User_AI caused an unexpected exception, contact your administrator: User_AI: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0UR0000003jSkcMAE; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Instructor__c, original object: User: []: Trigger.User_AI: line 42, column 1

Hello Everyone

Please may I have some help, I have this trigger and it is not firing. Can someone please take a look for me.

trigger updateRates on Rate_Type_del__c (after update) {
  
Set<Id> RateTypedelids = new Set<Id>();
    list <Account> newratelist = new list <Account>();
   
    for(Rate_Type_del__c rate:trigger.new){
        RateTypedelids.add(rate.id);
}
    List <Account> ratelist =[Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id in:RateTypedelids];
                                                 
      for(Rate_Type_del__c temprate:trigger.new){
      for(Account tempacc:ratelist){
      if(temprate.Company_del__c == tempacc.id && temprate.RecordType.Name == 'SureSwipe Base Rates' && temprate.Status__c == 'Active'){
{
    tempacc.Rate_Type__c = temprate.Rate_Type__c;
    tempacc.Fixed_Credit_Card_Rate__c = temprate.Number_Credit_Card_Fee__c;
    tempacc.Fixed_Debit_Card_Rate__c = temprate.Number_Debit_Card_Fee__c;
}
          }
        update newratelist;
    }
}

}
  • September 04, 2014
  • Like
  • 0

Hi,

 

I am trying to find how to locate the 15-digit Salesforce ID of a given custom object. I need this to dynamically create a record type selection link:

 

/setup/ui/recordtypeselect.jsp?ent= <Salesforce_ID_Of_Custom_Object>

 

For standard objects its fine to simply enter the object name in the 'ent' parameter, but for custom objects it requires the Salesforce ID (which is the one you find if you look at the URL when editing that particular object. I understand getKeyPrefix() within the DescribeResult gives you the first three digits but there does not seem to be a way of getting the entire 15-digit ID. 

 

Hope someone can help me out. 

Hi

I need to create a document set in sharepoint online from salesforce after creating a new account record, how to achieve this.

I have gone through the Files connect and lightning connect both are having only the read the columns and files from sharepoint but the write operation from salesforce to sharepoint is not possible.

Is there any other way to create/update a sharepoint custom column from salesforce

Thanks
Dinesh