• mike_merino
  • NEWBIE
  • 0 Points
  • Member since 2014
  • CZar
  • Mercury Payment Systems

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
For security reasons, I am using a protected custom metadata field to hold sensitive information in a managed package.  

I built a custom metadata type called Rest_id__mdt with one custom field: Value__c.  When I click "Manage Rest Ids" I entered values for username, client_secret, etc.

Within an apex class I have this code:
------------------------------------------
      Map<String,String> ridMap = new Map<String,String>();
      for (Rest_Id__mdt r2 : [SELECT MasterLabel, QualifiedApiName, value__c FROM Rest_Id__mdt]) 
      {
   //      System.debug(r2.MasterLabel + ' : ' +  r2.value__c +' -- ' +  r2.QualifiedApiName );
         ridMap.put(r2.MasterLabel, r2.value__c);
      }
    String clientId = ridMap.get('Client Id');
    String clientSecret = ridMap.get('Client Secret');
    String username = ridMap.get('Username');   // target
    String password = ridMap.get('pw+token');   // target
    String endpoint1 = ridMap.get('Endpoint');
    String endpoint2 = ridMap.get('Endpoint2');
  
    system.debug('### grant access - clientid '+clientid);
    String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
------------------------------------------
the debug statement in the source org, shows that this code correctly assigns the String variables with custom metadata data. Here is the debug log for this, where Vantiv1 is the namespace
14:43:49:039 SOQL_EXECUTE_BEGIN [27]|Aggregations:0|SELECT MasterLabel, QualifiedApiName, Vantiv1__Value__c FROM Rest_Id__mdt
14:43:49:041 SOQL_EXECUTE_END [27]|Rows:6

I built a managed package with this but in my installed org, in dev console I see this
14:55:53:003 SOQL_EXECUTE_BEGIN [27]|Aggregations:0|SELECT MasterLabel, QualifiedApiName, Vantiv1__Value__c FROM Rest_Id__mdt
14:55:53:005 SOQL_EXECUTE_END [27]|Rows:0

and I get the error:
System.NullPointerException: Argument 1 cannot be null
(
Vantiv1)
',}

so this works in source org but when I installed it in another dev org, I get this error and I THINK it is related to the custom metadata type.  Any thoughts?
 
in a custom javascript button, I have an animated gif (ajax-loader.gif
A colleague wrote this js file for me (AnimatedShowHide.js)
==========================
var j$ = jQuery.noConflict();

var AnimatedImageAppender = (function () {

    var imgId = "img_" + Date.now();

    return {

        ImagePath: 'foo',

  AddAnimation: function () {
            var top = j$(window).height() / 2 - 50;
            var left = j$(window).width() / 2 - 50;
            var positionPart = "position: absolute; top:" + top + "px; left: " + left + "px;";
            var image = j$("<img style='display:block; " + positionPart + "' id='" + imgId + "' src='" + this.ImagePath + "'/>").appendTo(document.body);
        },


        RemoveAnimation: function () {
            var selector = "#" + imgId;
            j$(selector).remove();
        }
    };

}());
=================
I added both to my static resources as private resources

here is my button code (I want to show the animated gif while the apex convert class is running and hide it on completion)
====================
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")}
{!REQUIRESCRIPT("https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js")}
{!REQUIRESCRIPT("/resource/AnimationShowHide")}

try{

AnimatedImageAppender.ImagePath = "https://www.berneckers.com/images/ajax-loader2.gif";
AnimatedImageAppender.AddAnimation();

var newurl= sforce.apex.execute("ConvertLead", "doConvert",{leadID : "{!Lead.Id}"});

AnimatedImageAppender.RemoveAnimation();

newurl1 = String(newurl);
if(newurl1.indexOf('error')>-1 )
  {
    alert(newurl);
    document.location.reload(true);
  }
else
  {
     parent.location.href = newurl;  // at completion, refresh to Opportunity page
  }
}
}
catch(err) {
   txt="There was an error on this page.\n\n";
   txt+="Error description: " + err.description + "\n\n";
   txt+="Click OK to continue.\n\n";
   alert(txt);
   document.location.reload(true);
}
============
when I click the button, the class completes successfully but I see no gif indicating "in progress"

help please
We are integrated to a sql server database with some BAD data; now before I even begin I know the correct answer is "fix the $%^&*( data", but here is my problem

in the sql server system you can have a valid state and country is null
in our integration system, we map these two values to the new SFA country and state picklist values.

Occasionally we'll get an error like this:
Upsert Error for record id : 181576 - Error in fields: OtherState - 
    Error Message: A country must be specified before specifying a state value for field:
    Owner State/Province. Error Code: FIELD_INTEGRITY_EXCEPTION

and again, the "right" answer is fix the source data, but I thought I could be clever and use the SFA order of execution
3.Executes all before triggers.
4.Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.

so I built a before trigger like this
==============================
trigger ContactBefore on Contact (before insert, before update) {
Trigger_on_off__c TriggerOnOff = Trigger_on_off__c.getInstance();

if (TriggerOnoff.Contact__c == true)
{
  
   for (Contact c: Trigger.new)
   {

     system.debug('### 2 '+c.MailingState+'--'+c.MailingCountry+'--'+c.MailingCountryCode);
     if (c.MailingCountry==null || c.mailingcountrycode==null)
     {
      c.MailingCountry='US';
      c.MailingCountryCode ='US';
     }
      if (c.otherCountry==null || c.otherCountrycode==null)
     {
      c.OtherCountry ='US';
      c.OtherCountryCode ='US';
     }
   }
}

}========================
here is what the debug log shows

12:38:41.402 (402058000)|CODE_UNIT_FINISHED|VerifyContactMPSEmail on Contact trigger event BeforeUpdate for [003C000001EeyZ0]
12:38:41.408 (408462000)|CODE_UNIT_STARTED|[EXTERNAL]|01qL00000004UEi|ContactBefore on Contact trigger event BeforeUpdate for [003C000001EeyZ0]
12:38:41.408 (408659000)|SYSTEM_METHOD_ENTRY|[22]|Trigger_On_Off__c.getInstance()
12:38:41.408 (408807000)|SYSTEM_METHOD_EXIT|[22]|Trigger_On_Off__c.getInstance()
12:38:41.408 (408867000)|SYSTEM_METHOD_ENTRY|[27]|LIST<Contact>.iterator()
12:38:41.408 (408891000)|SYSTEM_METHOD_EXIT|[27]|LIST<Contact>.iterator()
12:38:41.408 (408904000)|SYSTEM_METHOD_ENTRY|[27]|system.ListIterator.hasNext()
12:38:41.408 (408918000)|SYSTEM_METHOD_EXIT|[27]|system.ListIterator.hasNext()
12:38:41.408 (408968000)|SYSTEM_METHOD_ENTRY|[29]|MAP<Id,Contact>.get(Object)
12:38:41.408 (408994000)|SYSTEM_METHOD_EXIT|[29]|MAP<Id,Contact>.get(Object)
12:38:41.409 (409081000)|SYSTEM_METHOD_ENTRY|[30]|System.debug(ANY)
12:38:41.409 (409103000)|USER_DEBUG|[30]|DEBUG|### 2 CA--null--null
12:38:41.409 (409110000)|SYSTEM_METHOD_EXIT|[30]|System.debug(ANY)
12:38:41.409 (409204000)|SYSTEM_METHOD_ENTRY|[27]|system.ListIterator.hasNext()
12:38:41.409 (409220000)|SYSTEM_METHOD_EXIT|[27]|system.ListIterator.hasNext()

so you can see; the value of mailingState is CA (not null) and the value of mailingCountryCode is null
BUT the two statements in the IF statement are NOT executed ; why???
For security reasons, I am using a protected custom metadata field to hold sensitive information in a managed package.  

I built a custom metadata type called Rest_id__mdt with one custom field: Value__c.  When I click "Manage Rest Ids" I entered values for username, client_secret, etc.

Within an apex class I have this code:
------------------------------------------
      Map<String,String> ridMap = new Map<String,String>();
      for (Rest_Id__mdt r2 : [SELECT MasterLabel, QualifiedApiName, value__c FROM Rest_Id__mdt]) 
      {
   //      System.debug(r2.MasterLabel + ' : ' +  r2.value__c +' -- ' +  r2.QualifiedApiName );
         ridMap.put(r2.MasterLabel, r2.value__c);
      }
    String clientId = ridMap.get('Client Id');
    String clientSecret = ridMap.get('Client Secret');
    String username = ridMap.get('Username');   // target
    String password = ridMap.get('pw+token');   // target
    String endpoint1 = ridMap.get('Endpoint');
    String endpoint2 = ridMap.get('Endpoint2');
  
    system.debug('### grant access - clientid '+clientid);
    String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
------------------------------------------
the debug statement in the source org, shows that this code correctly assigns the String variables with custom metadata data. Here is the debug log for this, where Vantiv1 is the namespace
14:43:49:039 SOQL_EXECUTE_BEGIN [27]|Aggregations:0|SELECT MasterLabel, QualifiedApiName, Vantiv1__Value__c FROM Rest_Id__mdt
14:43:49:041 SOQL_EXECUTE_END [27]|Rows:6

I built a managed package with this but in my installed org, in dev console I see this
14:55:53:003 SOQL_EXECUTE_BEGIN [27]|Aggregations:0|SELECT MasterLabel, QualifiedApiName, Vantiv1__Value__c FROM Rest_Id__mdt
14:55:53:005 SOQL_EXECUTE_END [27]|Rows:0

and I get the error:
System.NullPointerException: Argument 1 cannot be null
(
Vantiv1)
',}

so this works in source org but when I installed it in another dev org, I get this error and I THINK it is related to the custom metadata type.  Any thoughts?
 
Need a little help. I can't figure out the correct syntax to utilize Task What.Type in my trigger. Can someone tell me what I am doing wrong?
 
trigger ININRelatedToFix on Task (after Insert, after Update) {
    
    //Get Record Type    
    RecordType Five9Rec = [select id from RecordType where name = 'Five9 Call' AND sobjecttype = 'Task' limit 1];
    system.debug('RecordType= '+Five9Rec.Id);
    
    //Create List for bulkified update
    List<Task> taskList = new List<Task>();
    
    //Loop through each task handed to trigger
    for (Task T : Trigger.new) {
        
        //If Call is related to Employee Session instead of Employee
        //*******************
        If(T.What.Type.equals('Employee_Session__c') && T.RecordTypeId == Five9Rec.Id){
            
            //Get the employee
            Employee_Session__c Emp = [Select Employee__c FROM Employee_Session__c WHERE ID = :T.WhatId];
            
            //Fix Relationship
            T.WhatId = Emp.Employee__c;
            taskList.add(t);
        }
    }
    
    //Builify Update
    update tasklist;
}

 
in a custom javascript button, I have an animated gif (ajax-loader.gif
A colleague wrote this js file for me (AnimatedShowHide.js)
==========================
var j$ = jQuery.noConflict();

var AnimatedImageAppender = (function () {

    var imgId = "img_" + Date.now();

    return {

        ImagePath: 'foo',

  AddAnimation: function () {
            var top = j$(window).height() / 2 - 50;
            var left = j$(window).width() / 2 - 50;
            var positionPart = "position: absolute; top:" + top + "px; left: " + left + "px;";
            var image = j$("<img style='display:block; " + positionPart + "' id='" + imgId + "' src='" + this.ImagePath + "'/>").appendTo(document.body);
        },


        RemoveAnimation: function () {
            var selector = "#" + imgId;
            j$(selector).remove();
        }
    };

}());
=================
I added both to my static resources as private resources

here is my button code (I want to show the animated gif while the apex convert class is running and hide it on completion)
====================
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")}
{!REQUIRESCRIPT("https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js")}
{!REQUIRESCRIPT("/resource/AnimationShowHide")}

try{

AnimatedImageAppender.ImagePath = "https://www.berneckers.com/images/ajax-loader2.gif";
AnimatedImageAppender.AddAnimation();

var newurl= sforce.apex.execute("ConvertLead", "doConvert",{leadID : "{!Lead.Id}"});

AnimatedImageAppender.RemoveAnimation();

newurl1 = String(newurl);
if(newurl1.indexOf('error')>-1 )
  {
    alert(newurl);
    document.location.reload(true);
  }
else
  {
     parent.location.href = newurl;  // at completion, refresh to Opportunity page
  }
}
}
catch(err) {
   txt="There was an error on this page.\n\n";
   txt+="Error description: " + err.description + "\n\n";
   txt+="Click OK to continue.\n\n";
   alert(txt);
   document.location.reload(true);
}
============
when I click the button, the class completes successfully but I see no gif indicating "in progress"

help please

Hi Everyone,

                              I am new to apex so this should be a simple question. I have a custom object with string fields. No duplicate should occur in any of these fields(before insert and before update).

                              I just want to add the duplictes to a list and in the end allow insert only if the list is NULL.

  • September 24, 2013
  • Like
  • 0