• Hazee.Li
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi All,
We've just enabled the Middle Name and Suffix Fields feature and encountered the below issue.

SUMMERY : Just after enabling "Middle Name and Suffix Fields", Implementation of custom apex logic in a static method vs running similar code snippet separately in an anonymous apex gives different result;

Runing as a method : null pointer exception (no middleName field)
Runing as anonymous : works fine!

DESCRIPTION : Below code throws an error while trying to access the middle name field in a static method,
 
private static Map<String,String> compHistoryObjDevNameToFieldName; 
// this will hold field name to label in order to access as a cache
	/**
	 * Returns:   field label of the object
     * field label  name will  return  from  compHistoryObjDevNameToFieldName if the value 
     * is cached in compHistoryObjDevNameToFieldName map it will return the value directly
     * or if  the  value  does  not exsist the logic will  cache the  new value and return
     **/ 
    public static String getFieldLabel(Id objectId, String fieldName) {
        // prepare the key of the map ObjectId prefix+fieldname 
        String recordPrefix = objectId.getSobjectType().getDescribe().getKeyPrefix(); 
        String ObjDevNameKey = recordPrefix + fieldName;
        
        //1. initialse map
        //if the map is null initialize the instance
        if (compHistoryObjDevNameToFieldName == null) {
            compHistoryObjDevNameToFieldName = new Map<String,String>();
        }

        //if the key is not contains add the nmew field to the map
        if (!compHistoryObjDevNameToFieldName.containsKey(ObjDevNameKey)) {
			Schema.DescribeSobjectResult objDesc = objectId.getSobjectType().getDescribe();
			compHistoryObjDevNameToFieldName.put(ObjDevNameKey, 
                                    objDesc.fields.getMap().get(fieldName).getDescribe().getLabel());
        }

        // return the field label
        return compHistoryObjDevNameToFieldName.get(ObjDevNameKey);
    }

However while debugging this issue, we found that if we access the fields.getMap() directly in an
anonymous execution, this gives the expected result.


Please refer the code executed in an anonymous window;
 
//Id objectId = '0011900000ApDykAAF'; // Person Account
//Id objectId = '0011900000BvwU6'; // Organisation
Id objectId = '0031900000AvXtg'; // Contact

// Accessing the method which contains the similar logic
try{
    // System.NullPointerException: Attempt to de-reference a null object at this point
    system.debug('Result::' + LibUtil.getFieldLabel(objectId, 'MiddleName'));
} catch(Exception e) {
    system.debug('Exception::' + e);
}

// implementing the similar logic(same set of code contains inside the method 
// LibUtil.getFieldLabel()) in anonymous window
Schema.DescribeSobjectResult objDesc = objectId.getSobjectType().getDescribe();
Map<String,Schema.SObjectField> fieldMapForLabel = objDesc.fields.getMap();
for(String key : fieldMapForLabel.keySet()){
    system.debug('DEBUG :: '+objDesc.fields.getMap().get(key));
}

Thanks in advance
 
I have been trying to save array of records with smartSync, unfortunatly smartSync does not provide a way to save an array at once. What I had to do was that iterate through the array with calling the save method for each object/record, which causes the slowliness of my mobile app. 
Apperently I found that there is a saveAll method though it saves records only to the cache which does not fullfill my requirnment (I need to save all the records in one call to SFDC).

my question is, is there a way to save collection/array of records at once with smartSync?


Hi All,
We've just enabled the Middle Name and Suffix Fields feature and encountered the below issue.

SUMMERY : Just after enabling "Middle Name and Suffix Fields", Implementation of custom apex logic in a static method vs running similar code snippet separately in an anonymous apex gives different result;

Runing as a method : null pointer exception (no middleName field)
Runing as anonymous : works fine!

DESCRIPTION : Below code throws an error while trying to access the middle name field in a static method,
 
private static Map<String,String> compHistoryObjDevNameToFieldName; 
// this will hold field name to label in order to access as a cache
	/**
	 * Returns:   field label of the object
     * field label  name will  return  from  compHistoryObjDevNameToFieldName if the value 
     * is cached in compHistoryObjDevNameToFieldName map it will return the value directly
     * or if  the  value  does  not exsist the logic will  cache the  new value and return
     **/ 
    public static String getFieldLabel(Id objectId, String fieldName) {
        // prepare the key of the map ObjectId prefix+fieldname 
        String recordPrefix = objectId.getSobjectType().getDescribe().getKeyPrefix(); 
        String ObjDevNameKey = recordPrefix + fieldName;
        
        //1. initialse map
        //if the map is null initialize the instance
        if (compHistoryObjDevNameToFieldName == null) {
            compHistoryObjDevNameToFieldName = new Map<String,String>();
        }

        //if the key is not contains add the nmew field to the map
        if (!compHistoryObjDevNameToFieldName.containsKey(ObjDevNameKey)) {
			Schema.DescribeSobjectResult objDesc = objectId.getSobjectType().getDescribe();
			compHistoryObjDevNameToFieldName.put(ObjDevNameKey, 
                                    objDesc.fields.getMap().get(fieldName).getDescribe().getLabel());
        }

        // return the field label
        return compHistoryObjDevNameToFieldName.get(ObjDevNameKey);
    }

However while debugging this issue, we found that if we access the fields.getMap() directly in an
anonymous execution, this gives the expected result.


Please refer the code executed in an anonymous window;
 
//Id objectId = '0011900000ApDykAAF'; // Person Account
//Id objectId = '0011900000BvwU6'; // Organisation
Id objectId = '0031900000AvXtg'; // Contact

// Accessing the method which contains the similar logic
try{
    // System.NullPointerException: Attempt to de-reference a null object at this point
    system.debug('Result::' + LibUtil.getFieldLabel(objectId, 'MiddleName'));
} catch(Exception e) {
    system.debug('Exception::' + e);
}

// implementing the similar logic(same set of code contains inside the method 
// LibUtil.getFieldLabel()) in anonymous window
Schema.DescribeSobjectResult objDesc = objectId.getSobjectType().getDescribe();
Map<String,Schema.SObjectField> fieldMapForLabel = objDesc.fields.getMap();
for(String key : fieldMapForLabel.keySet()){
    system.debug('DEBUG :: '+objDesc.fields.getMap().get(key));
}

Thanks in advance
 
Hey all, looking for some guidence.

I just recently started using Campaign Members to track training attendees because I wanted to keep it native. While Campaign Members object has some pros, it lacks many features, even basic features. For example, I can't send someone an email, track it, or set up tasks from the object record, like I can any other objects. 

Are there any apps out there or other ideas on how to managage event (campaign) attendees, other than just creating a new custom object?

Thank you, in advance! 

Hi,

 

I have read the Apex concepts but I am not getting enough confidence in Apex coding, probably I need to practice more.

I was looking for Apex code examples/samples and use cases in google, but couldnt get any.

Can you please let me know if you have links to the Apex code examples/samples and use cases for Apex to try practicing.

 

Also for Apex classes and triggers, please let me know the following:

 

1. On which parts of Apex, I need to start for code practice and how to proceed further.

2. While practicing, what should be the areas that I need to practice more

3. What areas of Apex are commonly used

4. What areas of Apex are complex which needs more practice

5. How to frame the use cases myself for Apex code practice.

 

 

Thanks,

Priya.

Simply updating the event does not send out the invites. Is there a way via apex to send updates to attendees when an event is updated?

Simply updating the event does not send out the invites. Is there a way via apex to send updates to attendees when an event is updated?