• pchadha20
  • NEWBIE
  • 25 Points
  • Member since 2008

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

I have a trigger that I am firing on cases before update.  After the contacts are created, I am trying to update the contact lookup (reference) field on the case.

 

Here is what I am trying:

 

trigger InsertCaseContact on Case (before update) { //Create a new list for caseIds List<Id> caseIds = new List<Id>{}; //Loop through the Cases we're adding and build a list of Ids for(Case cas: Trigger.new) caseIds.add(cas.Id); List<Contact> addContacts = new List<Contact>(); // Loop through the Trigger.new array of Cases. for(Case cas:Trigger.new){ if (cas.SuppliedName != null) { addContacts.add(new Contact (LastName = cas.SuppliedName, Email = cas.SuppliedEmail, Phone = cas.SuppliedPhone, Email_ExtID__c = cas.SuppliedEmail)); } } upsert addContacts Email_ExtID__c; // loop thru contacts to retrieve contact ids List<Contact> newContacts = new List<Contact>(); for (Contact c: addContacts) { newContacts.add(c); } List<Case> cases = new List<Case>{}; for (Case c : Trigger.new) { c.ContactId = newContacts.Id; cases.add(c); } update cases; }

 


Save error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Contact

 

How can I update the contact reference field in the cases with with the list of new contacts?

 

Thanks for any help.

Hi Guys,

I am trying to write the test method for below mention controller but not able to write. This class is calling ReCaptcha service. I am new to this , please help me out.

 

public  class SA_CFX_Password_Reset_Controller {

    private static string secret = '6LdecwwAAAAAALtIuEKANEv7lgzQNGzMAluFXSHk ';
    public string publicKey { get { return '6LdecwwAAAAAAIqUiXkcEJ_-V1U99uwCm-S4OXuY ' ; }} 

    private static string baseUrl = 'http://api-verify.recaptcha.net/verify'; 
     
    public string challenge {get; set;} { challenge = null; } 
    public string response {get; set; }  { response = null; } 
    public string message {get; set;} { message = null; } 

    public Boolean correctResponse { get; private set; } { correctResponse = false; } 
    
    public Account acc;
       
    public void SA_CFX_Password_Reset_Controller()
    {
        //Constructor
    }
    
    public Account getacc()
    { 
        if (acc == null) 
            acc = new Account();
        return acc;
    }
 
    public PageReference verify() {
      
    try { 
          if ( challenge == null || response == null ) { 
            
            return null; 
          }
                    
          HttpResponse r = makeRequest(  baseUrl ,
               'privatekey='+ secret + 
               '&remoteip=' + remoteHost + 
               '&challenge=' + challenge +
               '&response=' + response +
               '&error=incorrect-captcha-sol'
          );
        
          if ( r != null ) {  // is null when test methods run
            correctResponse = ( r.getBody().contains('true') );
          }
          
          if(correctResponse == true) {              
                Account Acct = [select Id, SA_CFX_Primary_Contact_eMail__c, SA_CFX_Reset_OTP__c, (Select Id,Password__c, User_Id__c, Flag__c  From CFX_Trading_Accounts__r) from Account where SA_CFX_Primary_Contact_eMail__c = :acc.SA_CFX_Primary_Contact_eMail__c ];
                CFX_Trading_Account__c[] tdacc = Acct.CFX_Trading_Accounts__r;
                
                list <CFX_Trading_Account__c> tacc = new list<CFX_Trading_Account__c>();
                for(Integer i=0; i<tdacc.size(); i++)
                {   
                    if(i == 0){
                      tdacc[i].Flag__c = true;
                    }
                    SA_CFXPasswordGenerator PassGen = new SA_CFXPasswordGenerator();
                    String pd = PassGen.randomPassword();
                    tdacc[i].Password__c = pd;
                    tacc.add(tdacc[i]);         
                    
                }
                                
                if(tacc.size()>0){                  
                    Database.SaveResult[] lsr = Database.update(tacc,true);
                    
                    for(Database.SaveResult sr : lsr){
                        if(sr.isSuccess()){
                          
              return Page.SA_CFX_Password_Reset_Successful;
              
                        }
                        else{
                            return Page.SA_CFX_Password_Reset_Failure;
                        }
                    }
                }
                else {
                    
                    return Page.SA_CFX_Password_Reset_Failure;
                }
                
          }  
        response = null;
        challenge = null;  
        message = 'Yes';
        return null;
   }
   
   catch (Exception e)  {
     ApexPages.addMessages(e);
     return null;
     
   }
        
 }    
       
   

    public PageReference reset() {
        challenge = null;
        response = null; 
        return null; 
    }   

    public static HttpResponse makeRequest(string url, string body)  {
          HttpRequest req = new HttpRequest();   
          HttpResponse response = null;
          req.setEndpoint( url );
          req.setMethod('POST');
          req.setBody ( body);
          try {
            Http http = new Http();
            response = http.send(req);
            System.debug('response: '+ response);
            System.debug('body: '+ response.getBody());
           
          } catch( System.Exception e) {
             System.debug('ERROR: '+ e);
          }
          return response;
        }   
    
    public PageReference close()
    {
        return null;
    }
  
    public PageReference close1()
    {   
        PageReference pg = page.ResetOTP ;
        pg.setRedirect(true);
        return pg; 
        return null;
    }
    
    
    public string remoteHost { get { string ret = '127.0.0.1';
        // also could use x-original-remote-host 
        map<string , string> hdrs = ApexPages.currentPage().getHeaders();
        if ( hdrs.get('x-original-remote-addr') != null)
            ret =  hdrs.get('x-original-remote-addr');
        else if ( hdrs.get('X-Salesforce-SIP') != null)
            ret =  hdrs.get('X-Salesforce-SIP');
        return ret;
    } }
    

 

Many Thanks,

pchadha20

My CLI has a SOQL with a '<' and a '>' condition.  Getting this error

 

110 [main] ERROR com.salesforce.lexiloader.process.ProcessConfig  - Error loading process: SFDCCaseExtractProcess configuration from config file: C:\Extraction\Beans\process-conf.xml
org.springframework.beans.factory.BeanDefinitionStoreException: Line 22 in XML document from file [C:\Extraction\Beans\process-conf.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The value of attribute "value" associated with an element type "entry" must not contain the '<' character.
org.xml.sax.SAXParseException:

 

The value of attribute "value" associated with an element type "entry" must not contain the '<' character.
 

 

Is '<' operator not supported by CLI in a SOQL.

 

Is there a substitution variable i can use?

Plz suggest.

 

Regards

Sunil Nandipati.

I have a trigger that I am firing on cases before update.  After the contacts are created, I am trying to update the contact lookup (reference) field on the case.

 

Here is what I am trying:

 

trigger InsertCaseContact on Case (before update) { //Create a new list for caseIds List<Id> caseIds = new List<Id>{}; //Loop through the Cases we're adding and build a list of Ids for(Case cas: Trigger.new) caseIds.add(cas.Id); List<Contact> addContacts = new List<Contact>(); // Loop through the Trigger.new array of Cases. for(Case cas:Trigger.new){ if (cas.SuppliedName != null) { addContacts.add(new Contact (LastName = cas.SuppliedName, Email = cas.SuppliedEmail, Phone = cas.SuppliedPhone, Email_ExtID__c = cas.SuppliedEmail)); } } upsert addContacts Email_ExtID__c; // loop thru contacts to retrieve contact ids List<Contact> newContacts = new List<Contact>(); for (Contact c: addContacts) { newContacts.add(c); } List<Case> cases = new List<Case>{}; for (Case c : Trigger.new) { c.ContactId = newContacts.Id; cases.add(c); } update cases; }

 


Save error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Contact

 

How can I update the contact reference field in the cases with with the list of new contacts?

 

Thanks for any help.

If I have an "after insert" trigger, I can use something like the following to determine whether a particular field has changed:

if (Trigger.old[0].myfield__c != Trigger.new[0].myfield__c) {
    // field changed
}
else {
    // field didn't change
}
 
Right?

If Trigger.old and Trigger.new have more than one record (because the trigger fired due to several records being changed at once), can I be certain that the records in Trigger.old and Trigger.new are always in the same order? In other words, can I assume that Trigger.old[x] and Trigger.new[x] refer to the same record?

Thanks,

Jeri