Hi in the below code value am adding values to account_name the after that using that adapter doing the set adapter.response is coming the server but values are not adding to the list and list is also displaying.  For displaying used the recyclerview to display the values .  can any one help me where did the mistake  Error:  java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean)' on a null object reference         at com.genworks.oppm.Adapter.MyAdapter.onCreateViewHolder(MyAdapter.java:32)         at com.genworks.oppm.Adapter.MyAdapter.onCreateViewHolder(MyAdapter.java:19)   updated code:  Activity.java:  for(SyncBlocks syncBlocks1:syncBlocks){                          String label=syncBlocks1.getLabel();                          ArrayList&lt;SynFields&gt; synFields=syncBlocks1.getFields();                          ArrayList&lt;SynFields&gt; jsonArray=syncBlocks1.getFields();                          for(SynFields synFields1:synFields){                              String name=synFields1.getName();                              Object values = synFields1.getValue().toString();                              try {                                  if (values instanceof JSONObject) {                                     JSONObject jsonObject1 = new                                             JSONObject(String.valueOf(synFields1.getValue()));                                     String value=jsonObject1.getString("value");                                 }else if (values instanceof String) {                                     //here, you get string                                       String value =  synFields1.getValue().toString();                                     //account_name.addAll(value);                                     String value_names= String.valueOf(synFields1.getValue());                                    // Log.e("account_name", String.valueOf(account_name.add(value)));                                     account_name.add(value_names);                                      //account_name.add(value);                                  }                              } catch (JSONException e) {                                 e.printStackTrace();                             }                          }                          myAdapter = new MyAdapter(getContext(),account_name);                         recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));                         recyclerView.setAdapter(myAdapter);                      }   MyAdapter.java:     public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.MyViewHolder&gt; {      private LayoutInflater inflater;     private Context mContext;     private ArrayList&lt;String&gt; mSynFields=new ArrayList&lt;&gt;();      public MyAdapter(Context context, ArrayList&lt;String&gt; synFieldsArrayList) {         mContext=context;         mSynFields=synFieldsArrayList;     }     @Override     public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {          View view = inflater.inflate(R.layout.fragment_account, parent, false);         MyViewHolder holder = new MyViewHolder(view);          return holder;     }      @Override     public void onBindViewHolder(MyViewHolder holder, int position) {         holder.name.setText(mSynFields.get(position));       }      @Override     public int getItemCount() {          return mSynFields.size();     }      class MyViewHolder extends RecyclerView.ViewHolder{          TextView country, name, city;         ImageView iv;          public MyViewHolder(View itemView) {             super(itemView);              country = (TextView) itemView.findViewById(R.id.headingText);             name = (TextView) itemView.findViewById(R.id.subHeaderText);             city = (TextView) itemView.findViewById(R.id.subHeadingText);         }      } }
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
119160
This Trigger is on lead (Before Insert, Before Update) and it errors (System.NullPointerException: Attempt to de-reference a null object). I'm getting this error when i'm posting "Web to Lead". However i do have the right ORG iD and Record type id included on the xml file:   &lt;input type=hidden name="oid" value="xxxxxxxxxxxxx"&gt; &lt;input type=hidden name="recordType" id="recordType" value="zzzzzzzzzzzzzzzzzz"&gt;    trigger IAAILeadTrigger on Lead (before insert, before update){ //BEGIN: S-444340 T-561808 - Process only IAA Remarketing Recordtype data     Map&lt;ID,Schema.RecordTypeInfo&gt; rt_Map = Lead.sObjectType.getDescribe().getRecordTypeInfosById();      //Looks up the branches based on the Lead PostalCode     if(trigger.isBefore){          for(Lead ld : trigger.new){                      if (rt_map.get(ld.recordTypeID).getName().containsIgnoreCase('IAA Remarketing') )                if( trigger.isInsert ||                    (trigger.isUpdate &amp;&amp; ld.Branch__c == null) ||                   (trigger.isUpdate &amp;&amp; ld.PostalCode != trigger.oldMap.get(ld.id).PostalCode)               ){                   leads.add(ld);               }           }           }                 //Only check the leads that are in the lead list and NOT the full trigger.new list         if(!leads.isEmpty()){             LeadController.GetLeadBranches(leads);           }     }  }
110820
I'm currently making a callout to a 3rd party vendor and I'm getting a huge response. What is currently messing me up is this section:   "MessageSeq":13,"Description":"config file: config-qa1.txt\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false   As you can see here, the portion at the end of the Description value is ended with backslash double quote. If I attempt to parse this via the JSONParser I get an exception. Does anyone have an recommendations on how to resolve this?  Exception Message:  System.JSONException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries at [line:1, column:3699]  Updated with sample Code   public class ResponseWrapper{     // fields from JSON to auto map     public Integer messageSeq;     public String Description;     public String messageTS;     public Integer messageLevel;     public Boolean isSystemMessage;     // parsing fields     private ResponseWrapper theResponse;     private JSONParser parser;      public void parse(String jsonString){         parser = JSON.createParser(jsonString);         parseJSON();     }      private void parseJSON(){            while (parser.nextToken() != null) {             if (parser.getCurrentToken() == JSONToken.START_OBJECT) {                 theResponse = (ResponseWrapper)parser.readValueAs(ResponseWrapper.class);                            }         }     } }  String responseString = '{"MessageSeq":13,"Description":"config file: config-qa1.txt\"","MessageTS":"2014-02-17T14:46:58","MessageLevel":4,"IsSystemMessage":false}'; system.debug('\n\nBEFORE\n' + responseString); ****Place code in here to test such as ReplaceALL*** ResponseWrapper parser = new ResponseWrapper(); parser.parse(responseString);
101111
We've had a community deployment and my brain is fried and I just whipped up a quick class that is throwing the below error. What have I done wrong here?     Error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MSI_UserTrigger:   execution of AfterInsert caused by: System.StringException: Invalid   id: () : [] () : []: ()   What I am trying to accomplish is:   When a new user is created and is active, if they are linked to a ContactId and part of a specific profile (by name), add their ContactId to a Set&lt;ID> Then loop through contacts where the Id is in the set, and update the Community_User__c field to TRUE      Trigger:   trigger MSI_UserTrigger on User (after insert) {       if(Trigger.isAfter){          if(Trigger.isInsert){              MSIUserTriggerHandler.executeAfterInsert(Trigger.new);          }      } }      Class:   public with sharing class MSIUserTriggerHandler {     private static final String COMMUNITY_PROFILE = 'Community Knowledge User';     private MSIUserTriggerHandler() {}      public static void executeAfterInsert(List&lt;User&gt; newList){         setCreatedCommunityUsers(newList);     }      private static void setCreatedCommunityUsers(List&lt;User&gt; newList){         List&lt;User&gt; usersWithContacts = new List&lt;User&gt;();         List&lt;Contact&gt; contactsToUpdate = new List&lt;Contact&gt;();         Set&lt;ID&gt; contactIds = new Set&lt;ID&gt;();          for(User u: newList){             if(u.ContactId == null &amp;&amp; u.ContactId == ''){                 continue;             }             if((u.ContactId != null &amp;&amp; u.ContactId != '') &amp;&amp; u.Profile.Name == COMMUNITY_PROFILE &amp;&amp; u.isActive == true){                 contactIds.add(u.ContactId);             }         }          for(Contact c : [Select Id,Name,Community_User_Created__c from Contact where Id in :contactIds]){             if(!c.Community_User_Created__c){                 c.Community_User_Created__c = true;                 contactsToUpdate.add(c);             }         }         update contactsToUpdate;     } }   Am I not adding the ID correctly to the Set&lt;ID>, or am I querying wrong in my for(Contacts) loop?
77222
I have a really simple Java class that effectively decorates a Map with input validation, with the obvious void set() and String get() methods.  I'd like to be able to effectively call those methods and handle return values and exceptions from outside the JVM, but still on the same machine Update: the caller I have in mind is not another JVM; thanks @Dave Ray  My implementation considerations are typical    performance ease of implementation and maintenance (simplicity?) reliability flexibility (i.e. can I call from a remote machine, etc.)   Is there a 'right way?' If not, what are my options, and what are the pro/cons for each?  (Stuff people have actually done and can provide real-life feedback on would be great!)
14293
I need to loop through Accounts and then on all of the Contacts for those Accounts. I need to find what is the address with the most occurrences in Contacts for each Account and update the Account with that address. I can loop through Accounts and Contacts just fine but getting the address and finding the one that most Contacts have is getting tricky. This is my code so far:  public static void completeaddresses(){     List&lt;Account&gt; acctList = new List&lt;Account&gt;();     acctList = [SELECT Id, BillingState, BillingPostalCode, BillingCity,BillingStreet, BillingCountry, BillingAddress, (SELECT Id, contact.MailingAddress, contact.MailingStreet, contact.MailingCity, contact.MailingState, contact.MailingPostalCode, contact.MailingCountry FROM account.contacts WHERE contact.MailingStreet!='' OR contact.MailingCity!='' OR contact.MailingPostalCode!='' OR contact.MailingCountry!='' OR contact.MailingState!='') FROM Account WHERE BillingState ='' AND BillingPostalCode ='' AND BillingCity = '' AND BillingStreet = ''];      Map&lt;Address, Integer&gt; addresses = new Map&lt;Address, Integer&gt;();     List&lt;Address&gt; addressList = new List&lt;Address&gt;();      for (Account acct:acctList) {         for (Contact cont:acct.contacts) {             if (!addresses.containsKey(cont.MailingAddress)) {                 addresses.put(cont.MailingAddress,0);             }             Integer currentCount = addresses.get(cont.MailingAddress) + 1;             addresses.put(cont.MailingAddress, currentCount);         }         addressList.addAll(addresses.keySet());         addressList.sort();     } }   The issue is, it sorts by key not by value, if I could sort by value, then I can update the account and I'd be done. I'd appreciate if someone can let me know if I can sort by value and how. Thanks.
7898
The StackExchange app crashes for me on every start when I click a link in the browser. It seems (based on the StackTrace) that the url parser causes a null pointer exception. I'm using 0.1.90.
74634
I am trying to start share-point workflow using CSOM(Client side object model) by following means of code. But i got the following error from the line mark in comment. Please help me to figure out this error.     Error :- Cannot invoke method or retrieve property from null   object. Object returned by the following call stack is null.   "GetWorkflowDeploymentService new   Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager() "    public bool StartWorkFlow()  {     string workflowName = "UpdateDealStatus";     // connect to the workflow services via a CSOM client context    var workflowServicesManager = new WorkflowServicesManager(_sharepoint,                  _sharepoint.Web);    // connect to the deployment service    var workflowDeploymentService = workflowServicesManager.GetWorkflowDeploymentService();    // get all installed workflows   var publishedWorkflowDefinitions =    workflowDeploymentService.EnumerateDefinitions(true);             _sharepoint.Load(publishedWorkflowDefinitions);     try    {       _sharepoint.ExecuteQuery();//Error thrown from this line    }    catch (Exception ex)    {      }     // find the first workflow definition    var firstWorkflowDefinition = publishedWorkflowDefinitions.First();     // connect to the subscription service    var workflowSubscriptionService = workflowServicesManager.GetWorkflowSubscriptionService();     // get all workflow associations    var workflowAssociations = workflowSubscriptionService.EnumerateSubscriptionsByDefinition(firstWorkflowDefinition.Id);     _sharepoint.Load(workflowAssociations);    _sharepoint.ExecuteQuery();     foreach (var association in workflowAssociations)    {        Console.WriteLine("{0} - {1}",        association.Id, association.Name);    }     return true; }
40938
After I posted this question, I found a similar post that seemed to answer it: . I'll leave this in place for now, as I am not sure how to mark my own question as a duplicate  In attempting to debug a SOQL query error, I encountered a strange behavior with Database.query and bind variables. Specifically, when I run this code:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } Database.query(userQuery);   the Database.query statement executes with no errors, despite the fact that the variable firstNames does not exist in its context. However, when I add an else clause:  String userQuery = 'SELECT Id FROM User'; if (true) {     List&lt;String&gt; firstNames = new List&lt;String&gt;{'James','Joe'};     userQuery += ' WHERE FirstName IN :firstNames'; } else {     List&lt;String&gt; firstNames; } Database.query(userQuery);   I receive a null object reference exception. It seems like Salesforce is checking to see if the variable is only declared once beforehand and, if so, uses its value in the context it was declared. This seems strange to me, so I was wondering if anybody here has any insight into what is going on under the hood.
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today
68403
I have this controller but I am getting this error      System.QueryException: List has no rows for assignment to SObject   public class MyController {     private final Account account;      public MyController() {         account = [SELECT Id, Name, Site FROM Account                     WHERE Id = :ApexPages.currentPage().getParameters().get('id')];             }      public Account getAccount() {         return account;     }      public PageReference save() {         update account;         return null;     } }
33737
If you take a look into this issue     I have provide an answer of using set&lt;Sobject&gt; instead using list&lt;Sobject&gt;  i.e.  if( !contacts.values().isEmpty() ){   set&lt;Contact&gt; setContacts = new set&lt;Contact&gt;();   for( Contact objCon : contacts.values() ){     if(!setContacts.contains(objCon)){         setContacts.add( objCon );     }   }  update new list&lt;Contact&gt;(setContacts); }   even if(!setContacts.contains(objCon)) is not needed  if( !contacts.values().isEmpty() ){   set&lt;Contact&gt; setContacts = new set&lt;Contact&gt;();   for( Contact objCon : contacts.values() ){         setContacts.add( objCon );   }  update new list&lt;Contact&gt;(setContacts); }   So is there any condition/use case where this answer might fail?
122930
I'm comparing two list given in the list to see if the item.name exists in both for loop. If not then add into a list to show the error for the missing names.  set&lt;id&gt; setAssetIds = new set&lt;id&gt;(); list&lt;Asset_Store__c&gt;  assets = [select id,name......]; for(Asset_Store__c item : assets ) {     setAssetIds.add(item.id);  }   list&lt;Meter__c&gt;  meters = [select id,name......where id in : setAssetIds];  //now comparing the two lists for(Asset_Store__c a : assets) {    for(Meter__c m : meters)    {      if(a.Name != m.Name)      {        //not matched...        break;      }     } }   the problem with the above approach is that, its not finding the correct name.
79268
Here is my code `  global with sharing class ReportsListController {     public String dcarr { get; set; }    public static ReportsColumnMap__c repcols { get; set; }    public ReportsListController() { } // empty constructor    @RemoteAction   global static List&lt;ReportsColumnMap__c&gt; getRepCols(String dcarr) {             List&lt;ReportsColumnMap__c&gt; repcols =          [SELECT ColumnName__c,SObject__c ,COUNT(ID) FROM ReportsColumnMap__c WHERE ColumnName__c IN ('OWNER','FIRST_NAME','LAST_NAME','TITLE','COMPANY','LEAD_SOURCE','RATING','STREET','EMAIL') AND SObject__c !='null' GROUP BY SObject__c ,ColumnName__c];     return repcols;   } }   `
116361
I try to get the values ​​of the maps, but it is impossible with these codes     public static agregarAdicionales(Map&lt;String, String&gt; objPromociones) {             System.debug('objPromociones:: ' + objPromociones);          System.debug('objPromociones:: ' + objPromociones);                List &lt;Map&lt;String, String&gt;&gt; a = new List &lt;Map&lt;String, String&gt;&gt;();                          a.add(objPromociones);          System.debug('Lista de mapas:: ' + a);     System.debug('Lista Nombre promo de objeto &quot;a&quot;:: ' + a[0].get('ApexNombrePromo'));         for (String value : objPromociones.values()) {         /*String PromoNombre = objPromociones.get('ApexNombrePromo');         String PromoId = objPromociones.get('ApexIdPromo');         String esAutomatica = objPromociones.get('ApexPromoAutomatica');         Boolean PromoAutomatica = Boolean.valueOf(esAutomatica);                  String ProductoAdicional = objPromociones.get ('ApexAdicionalProductoNombre');         String ProductoAdicionalId = objPromociones.get ('ApexAdicionalProductoId'); */                        String i = objPromociones.get('ApexNombrePromo');                  System.debug(objPromociones);         System.debug('Value = ' + value.get('ApexNombrePromo'));          System.debug('i = ' + i);              }  I want to get the values ​​of &quot;ApexPromoName&quot;  USER_DEBUG [223]|DEBUG|Lista de mapas:: ({0={ApexNombrePromo=HBO por 2 Meses}, 1={ApexNombrePromo=Prueba - Promo 13})  I want to extract the value 'Apex PromoName', but it is impossible for me
73868
I need help. I am currently trying to test this code before uploading  public class CoreValuesExt { ApexPages.StandardController sc; public boolean readonly {get; set;} public Core_Values__c cv {get; set;} public integer countEdit = 1; public string buttonValue {get; set;} public integer recordScan;  public CoreValuesExt(ApexPages.StandardController sc) {     this.sc = sc;     cv = new Core_Values__c();     cv.Account__c = sc.getid();      readonly = true;     buttonValue = 'Edit';     recordScan = [SELECT COUNT() FROM Core_Values__c WHERE Account__c = :cv.Account__c];    if (recordScan != 0){    cv = [SELECT id, HSE__c, Professionalism_Integrity__c, Quality_Accuracy__c, Technology_Innovation__c, Timeliness__c, Value_for_money__c FROM Core_Values__c WHERE Account__c = :cv.Account__c];     }  }  public ApexPages.PageReference Save() {     return sc.Save(); }  public void ApplyAction() {     countEdit++;     Integer modolus = Math.mod(countEdit, 2);     String total = cv.HSE__c + cv.Professionalism_Integrity__c + cv.Quality_Accuracy__c + cv.Technology_Innovation__c + cv.Value_for_Money__c + cv.Timeliness__c;     if(modolus == 0)     {         readonly = false;         buttonValue = 'Save';     }     else     {         if(total != 'nullnullnullnullnullnull')            {         if (recordScan == 0){         insert cv;         readonly = true;         buttonValue = 'Edit';         }         else         {         update cv;         readonly = true;         buttonValue = 'Edit';         }         }     }    }   }  With this trigger.  trigger CoreValuesTrigger on Core_Values__c (before insert) {  Core_Values__c cvs = Trigger.new; CoreValuesExt.ApplyAction(cvs);  }   But when I try to save, I get a message saying:      Illegal assignment from List to   CoreValuesExt__Core_Values__c at line 3 column 1   "  How do I go through with this? I need help. Thanks
65747
I'm running a REST API which is returning the below:  "id" : "fdgsdgsdsdgsdg",    "pageevents" : [ {        "name" : "test",        "number" : "0123442",        "homepage" : "www.test.com"     } ],     "goals" : [ {        "name" : "test",        "number" : "0123442",        "homepage" : "www.test.com"     } ] } ]   Im using the below code to de-serialize it, so i can display it as a pageblocktable on a visualforce page however im getting the error :      System.JSONException: Illegal value for primitive   public List&lt;maMoments&gt; getMomentsActivity() {     Id contactId;     if (contactId == null) {         contactId = '0030O00001sqXJr';     }      String contactIdString = String.valueOf(contactId);     String jsonResponse = this.AutomationDetailsMoments(contactIdString);     system.debug(jsonResponse);     List&lt;maMoments&gt; mAutomation = (List&lt;maMoments&gt;) JSON.deserialize(jsonResponse, List&lt;maMoments&gt;.class);     system.debug(mAutomation);     for(maMoments emailStructure : mAutomation){      }      return mAutomation; }  public string AutomationDetailsMoments(String contactId) {     contactId = '0030O00001sqXJr';     Http h = new Http();     HttpRequest req = new HttpRequest();     req.setEndpoint('https://virtserver.swaggerhub.com/mickjdavies/Example/1.0.0/interestingmoments');     req.setMethod('POST');     req.setBody(contactId);      // Send the request, and return a response     HttpResponse res = h.send(req);     system.debug(res.getBody());     return res.getBody(); }  private class maMoments {     public String contactId;     public String id;     public List&lt;String&gt; goals;     public String name;     public String homepage;     public String phone; }