• Brad007
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 36
    Questions
  • 27
    Replies
Hi, I have a WSDL generated Apex class which i am using to perform apex callouts. I did not realize it requires a test class When i am trying to deploy my code to production my code percentage was screwed due to this WSDL Apex class which is huge. It has code which is out of my understanding as it is automatically generated by salesfroce. How would i able to write the test class, is there a way to by pass this. Any suggestions would be greatly appreciative. Thank you,
Hi, I have Scheduler class which is not initiating any other class but has a static method within. I had to build this class such a way as i had to make a apex call out and which needs to static. So my scheduler class works fine but i need a head start on how i can test the rest of the lines of code please check below for code and help me give a head start. /*The scheduler class fires hourly for the AP Files*/ global class APFiles_ScheduledHourlyRun implements Schedulable { global void execute(SchedulableContext sc) { APFilesMissing(); } @future(callout=true) public static void APFilesMissing() { // Exception log to capture various kind of errors as unable to make callouts, bad data or read time out issues. List errors = new List(); Datetime RuntimeCode = Datetime.newInstance(date.today(),time.newInstance(1, 11, 11, 0)); try { string ServiceResult = ''; // Creates list for Available Aupairs List APFiles = [Select a.Id ,a.Au_Pair__c,a.AP_Folder_Name__c, a.Photo4__c, a.Photo3__c, a.Photo2__c, a.Photo1__c, a.IsExist_Photo4__c, a.IsExist_Photo3__c, a.IsExist_Photo2__c, a.IsExist_Photo1__c,a.Au_Pair__r.Id,a.Au_Pair__r.AP_Status__c,a.Au_Pair__r.Record_Type_Name__c From AP_Application__c a where a.Au_Pair__r.AP_Status__c ='Available' AND a.Au_Pair__r.Record_Type_Name__c= 'Au Pair']; // Root of Xml string string XmlString = ''; //Create Xml record element for every APPhoto file with IsPhotoExist as false for(AP_Application__c APAppObj: APFiles) { if(APAppObj.IsExist_Photo1__c == false) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo1__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo2__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo2__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo3__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo3__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo4__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo4__c+''; XmlString += ''; } } //Close root Xml XmlString += ''; System.debug('XML:' +XmlString); // Create WSDL Stub for Call out GAPOrg.AjaxSoap servicestub = new GAPOrg.AjaxSoap(); servicestub.timeout_x = 9000; ServiceResult = servicestub.GAPAPFiles(XmlString); //System.debug('XmlResultfromService:' +xmldata); //Retrive the values from Xml using DOM class List Files = new List(); Dom.Document docx = new Dom.Document(); docx.load(ServiceResult); Dom.Xmlnode xroot = docx.getRootElement(); Dom.Xmlnode[] xrec = xroot.getChildElements(); for(Dom.Xmlnode child : xrec) { Files__c file = new Files__c(); for(Dom.Xmlnode node : child.getchildren()) { if(node.getName() == 'ApplicationId') { //system.debug('ApplicationId:' +node.gettext()); file.AP_Application__c = node.gettext(); } if(node.getName() == 'APID') { //system.debug('APID:' +node.gettext()); file.Contact__c = node.gettext(); } if(node.getName() == 'Filepath') { String[] path = node.gettext().split('/'); string filepath = +path[4]+'/'+path[5]+'/'+path[6]+'/'+path[7]; system.debug('Filepath:'+path[4]+'/'+path[5]+'/'+path[6]+'/'+path[7]); //system.debug('Filepath:' +node.gettext()); file.Path__c = filepath; } } Files.add(file); system.debug(File); } insert Files; } catch (Exception e) { Exception_Log__c ex = new Exception_Log__c(); ex.Exception_Code__c =''; ex.Error_Message__c = e.getMessage(); errors.add(ex); System.debug(e.getMessage()); } List nice = BusinessExceptionServices.SaveLogEntries(null,errors); errors.clear(); } } Thank in advance!

Hi ,

System.DmlException: Upsert failed. First exception on row 0 with id a1WV00000001HBKMA2; first error: MISSING_ARGUMENT, External_ID__c not specified: []

I have my upsert opration failing. Can any one please suggest whats wrong in the below code and how help fix the code.

public with sharing class APImageUpdatesGlobal {
    public void APFilesMissingGlobal()
        {
          string ServiceResult = '';  
          System.debug('Entered!');
      
          // Create list for Available Aupairs
          List<AP_Application__c> APFiles = [Select a.Photo4__c, a.Photo3__c, a.Photo2__c, a.Photo1__c, a.Id, a.External_ID_Photo4__c, a.External_ID_Photo3__c, a.External_ID_Photo2__c, a.External_ID_Photo1__c, a.Au_Pair__c From AP_Application__c a where a.Au_Pair__r.AP_Status__c ='Available' AND a.Au_Pair__r.Record_Type_Name__c= 'Au Pair'];      
          
          string XmlString = '<FilesData>';                
          for(AP_Application__c APFile: APFiles)
            {    
              XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo1__c+'</Path>';  
              XmlString += '<External_ID>'+APFile.External_ID_Photo1__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';  
              XmlString += '</APFiles>';    
              
                XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo2__c+'</Path>';
              XmlString += '<External_ID>'+APFile.External_ID_Photo2__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';
              XmlString += '</APFiles>';  
              
              XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo3__c+'</Path>';
              XmlString += '<External_ID>'+APFile.External_ID_Photo3__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';
              XmlString += '</APFiles>';  
              
              XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo4__c+'</Path>';  
              XmlString += '<External_ID>'+APFile.External_ID_Photo4__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';                
              XmlString += '</APFiles>';            
            }
              //Close root Xml
            XmlString += '</FilesData>';         
            GAPOrg.AjaxSoap Servicestub = new GAPOrg.AjaxSoap();
            ServiceResult = Servicestub.GAPAPFilesGlobalRun(XmlString);          
            Dom.Document docx = new Dom.Document();
              docx.load(ServiceResult);
              Dom.Xmlnode root = docx.getRootElement();
              List<Files__c> upsertfiles = new List<Files__c>(); 
              for(Dom.Xmlnode child : root.getChildElements())    {             
               Files__c file = null;           
               for(Dom.Xmlnode node : child.getChildElements())      {                  
                   if(node.getName() == 'External_ID') {                    
                     string str = node.getText();               
                          if( str != ''){
                             file = new Files__c();        file = [Select f.Path__c, f.Inactive_Date__c, f.Id, f.External_ID__c, f.Contact__c, f.AP_Application__c From Files__c f where f.External_ID__c =: node.gettext() limit 1 ];
                     }
                 } 
                 else if(node.getName() == 'Inactive_Dt')
                 {
                   if(file != null) {
                     if(node.getText() != ' ')
                     {
                      String[] stringDate = node.gettext().split('/');                     
                       Integer m =  Integer.valueOf(stringDate[0]);
                       Integer d = Integer.valueOf(stringDate[1]);
                       Integer y = Integer.valueOf(stringDate[2]);  
                      file.Inactive_Date__c = date.newinstance(y,m,d);                   
                     }
                   }
                 }
               }
               if (file == null) {  
               for(Dom.Xmlnode node : child.getChildElements())
               {
                  string str = node.getName();                 
                  file = new Files__c();                     
                 if(str == 'ApplicationId')
                 {    file.AP_Application__c = node.gettext();     }
                 else if(str == 'APID')
                 {  file.Contact__c = node.gettext();    }
                 else if(str == 'Path')
                 {   file.Path__c = node.gettext();   }
                 else if(str == 'Inactive_Dt')
                {
                 if(str != ' ')
                   {
                    String[] stringDate = node.gettext().split('/');                  
                     Integer m =  Integer.valueOf(stringDate[0]);
                     Integer d = Integer.valueOf(stringDate[1]);
                     Integer y = Integer.valueOf(stringDate[2]);  
                    file.Inactive_Date__c = date.newinstance(y,m,d);
                   }
                 }
               }
           }      
          upsertfiles.add(file);   
          file =null;                    
        }         
        try {   upsert upsertfiles External_ID__c;      }
        
          catch (DmlException e) {
                System.debug(e.getMessage());
           }    
     }
}

Hi I am doing a Apex callout and i need to get the Xml string data Map it and Upsert my Object. But i am confused here as with the Xml string data i have.  this is what i would get after my call out.

 

<APFilesData><APFiles1><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo1>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo1.jpg</Photo1><External_ID_Photo1>Test</External_ID_Photo1><InactivePhoto1_Dt>11/08/2011</InactivePhoto1_Dt></APFiles1><APFiles2><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo2>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo2.jpg</Photo2><External_ID_Photo2>null</External_ID_Photo2><InactivePhoto2_Dt></InactivePhoto2_Dt></APFiles2><APFiles3><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo3>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo3.jpg</Photo3><External_ID_Photo3>null</External_ID_Photo3><InactivePhoto3_Dt></InactivePhoto3_Dt></APFiles3><APFiles4><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo4>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo4.jpg</Photo4><External_ID_Photo4>null</External_ID_Photo4><InactivePhoto4_Dt></InactivePhoto4_Dt></APFiles4><APFilesData>

 

So now i have a files object which has a External_Id__c field which should be mapped to the above external Ids. and then if i have a Inactive date populated in my xml i update or i insert new row into files with 4 values.

 

Dom.Document docx = new Dom.Document();  

 docx.load(ServiceResult);    

 Dom.Xmlnode xroot = docx.getRootElement();    

 Dom.Xmlnode [] xrec = xroot.getChildElements();  

 Files__c[]  upsertfiles = new Files__c[]{};    

 List<AP_Application__c> upsertApplications = new List<AP_Application__c>();        

 for(Dom.Xmlnode child : xrec)

 {

     Files__c file = new Files__c();

     for(Dom.Xmlnode node : child.getchildren())

    {// What should go here to have my upsert   }

    upsertfiles.add(file);

    system.debug('Result:' +upsertfiles);

     try {       

            upsert upsertfiles External_ID__c;     }    

        catch (DmlException e)

      {        System.debug(e.getMessage());    } }

 

 



For each photo file, create one row to be inserted into Files__c in SFDC.  Need the following columns:

Files__c

From

Contact__c

AP_Application__c.Au_Pair__c

AP_Application__c

AP_Application__c

Path__c

AP_Application__c.Photo1__c

External_ID__c

AP_Application__c. ExernalIdPhoto1

Inactive_Date__c

New column you create

UPSERT  Files

Use External Id to match Files__c. ExternalId

Files__c. AP_Application__c  = Application id

Files__c.Contact__c = Contact id

Files__c.Path__c = Path

Files__c.Inactive_Dt__c

Hi, I am performing a Apex callout and am retreving data as a xml string. Now i would want to have my data used for Upsert Operation on Files__c Object.Below is how my xml 

<APFilesData>

<APFiles>

  <ApplicationId>a0B40000000vBJrEAM</ApplicationId>

  <APID>0034000000SiXLtAAN</APID>  <Photo1>//Bait/Applications/APApplications/AP0802720.Song/Photos/Photo1.jpg</Photo1>

           <Photo2>//Bait/Applications/APApplications/AP0802720.Song/Photos/Photo2.jpg</Photo2>

  <External_ID_Photo1>null</External_ID_Photo1>

           <External_ID_Photo2>null</External_ID_Photo2>

          <InactivePhoto1_Dt>11/10/2011 </InactivePhoto1_Dt>

  <InactivePhoto2_Dt></InactivePhoto2_Dt>

</APFiles>

</APFilesData>

  Below is how am retriving values           

System.debug('BharathXML:' +XmlString);
            GAPOrg.AjaxSoap Servicestub = new GAPOrg.AjaxSoap();
            ServiceResult = Servicestub.GAPAPFilesGlobalRun(XmlString);
            System.debug('XmlResult:' +ServiceResult);            
            
            Files__c  upsertfiles = new Files__c();
            Dom.Document docx = new Dom.Document();
            docx.load(ServiceResult);
            Dom.Xmlnode xroot = docx.getRootElement();

  Dom.Xmlnode [] xrec = xroot.getChildElements();

And the values that need to upserted for FIles__c are

For each photo file, create one row to be inserted into Files__c in SFDC.  Need the following columns:

Contact id  (from AP_Application__c.Au_Pair__c)

Application Id (from AP_Application__c.Id)

Path (AP_Application__c.Photo1__c)

External Id (AP_Application__c. ExernalIdPhoto1)

Inactive Dt (new column, will map to Files__c.Inactive_Dt__c)

Files__c.Inactive_Dt__c

UPSERT  Files

Use External Id to match Files__c. ExternalId

Files__c. AP_Application__c  = Application id

Files__c.Contact__c = Contact id

Files__c.Path__c = Path

Hi 

 

I am having the above error and i understand that its beacuse i am updating my object over and over . As the if contion is true i am updating again and again. Can anyone please suggest a  work around as how i can have updates even after if conditions.

trigger APFileUpdates on Files__c (after insert) {

    if(trigger.isInsert)
    {  
      System.debug('Trigger is fired.');
      List<Files__c> APFiles  = trigger.new;
      List<AP_Application__c> UpdateAPApp = new List<AP_Application__c>();
      //List<Files__c> processList= new List<Files__c>();       
        set<String> zips = new set<String>();
      string P1 = 'Photo1.jpg';
      string P2 = 'Photo2.jpg';
      string P3 = 'Photo3.jpg';
      string P4 = 'Photo4.jpg';      
      if(trigger.new != null && trigger.new.size() > 0)
      {
        System.debug('Trigger is fired.');
        for (Files__c file: APFiles)
        {  
          string path = file.Path__c;                      
          AP_Application__c App = [Select a.Id,a.IsExist_Photo1__c, a.IsExist_Photo2__c, a.IsExist_Photo3__c, a.IsExist_Photo4__c, a.Au_Pair__c,External_ID_Photo1__c From AP_Application__c a where id =: file.AP_Application__c ];             
          if(path.contains(p1))
          {
            App.IsExist_Photo1__c = true;
            App.External_ID_Photo1__c = file.External_ID__c;
            UpdateAPApp.add(App);  
          }          
          System.debug('APResultApplication:' +App);                      
          
          if(path.contains(p2))
          {              
            App.IsExist_Photo2__c = true;
            App.External_ID_Photo2__c = file.External_ID__c;
            UpdateAPApp.add(App);                        
          }
          if(path.contains(p3))
          {            
            App.IsExist_Photo3__c = true;
            App.External_ID_Photo3__c = file.External_ID__c;
            UpdateAPApp.add(App);                        
          }
          if(path.contains(p4))
          {             
            App.IsExist_Photo4__c = true;
            App.External_ID_Photo4__c = file.External_ID__c;
            UpdateAPApp.add(App);                        
          }
                          
        }
        update UpdateAPApp;
      }
      
    }
}

Thank you.

Hi, My Xml string which is returned from a webservice has the following few and the xml looks like this. I have been using XmlStream reader class to parse and i am unsuccessful . I need to get theese values updated to a custom object fields. Any help would be greatly appreciated.

 

Xmlstring = '<APFilesData>

<APFiles>

 <Id>a0B40000001xxxxxxx</Id>

<APID>0034000000Uxxxxxx</APID>

<Filepath>//Bait/Applications/AP Applications/AP0902905.Botia_Diaz/Photos/Photo1.jpg</Filepath></APFiles>

<APFiles>

<Id>a0B400000xxxxxxxx</Id>

<APID>0034000000xxxx</APID>

<Filepath>//Bait/Applications/AP Applications/AP0902905.Botia_Diaz/Photos/Photo2.jpg</Filepath></APFiles>

<APFiles>

<Id>a0B40000001xxxxx</Id>

<APID>0034000000Ulxxx</APID>

<Filepath>//Bait/Applications/AP Applications/AP0902905.Botia_Diaz/Photos/Photo3.jpg</Filepath></APFiles>

<APFiles>

<Id>a0B40000xxxxxx</Id>

<APID>0034000000Uxxx</APID>

<Filepath>//Bait/Applications/AP Applications/AP0902905.Botia_Diaz/Photos/Photo4.jpg</Filepath>    </APFiles>

                   </APFilesData>';

 

Thank you,

Hi, I am trying to make a Apex callout but facing various errors in it. one of them below is 

 

System.CalloutException: IO Exception: java.security.cert.CertificateException: No subject alternative names matching IP address xx.xx.xx.xxx found

 

Any suggestion or help would be greatly appreciated.

 

Thank you,

Hi,

 

I have been trying to perform the Apex callout . And i am stuck converting the Xml string back to a Object. And also i am receiving soem error trying to making the callout not sure if that was successful

   

I need to get the Values of string Xml in Apex and update to a object named Files. 

 

Please suggest thanks in Advance.

 

public class APImageUpdates {
  public void APFilesMissing()
    {
      string ServiceResult = '';
      System.debug('Entered!');
      
      // Create list for Available Aupairs
      List<AP_Application__c> APFiles = [Select  a.Id ,a.Au_Pair__c,a.AP_Folder_Name__c, a.Photo4__c, a.Photo3__c, a.Photo2__c, a.Photo1__c, a.IsExist_Photo4__c, a.IsExist_Photo3__c, a.IsExist_Photo2__c, a.IsExist_Photo1__c,a.Au_Pair__r.Id,a.Au_Pair__r.AP_Status__c,a.Au_Pair__r.Record_Type_Name__c  From AP_Application__c a where a.Au_Pair__r.AP_Status__c ='Available' AND a.Au_Pair__r.Record_Type_Name__c= 'Au Pair'];      
       
      // Root of the Xml list
      string XmlString = '<APFilesData>';      
                  
        for(AP_Application__c APAppObj: APFiles)
        {    
            if(APAppObj.IsExist_Photo1__c == false) 
            {  
              XmlString += '<APFiles>';
              XmlString += '<Id>';
              XmlString += APAppObj.Id;
              XmlString += '</Id>';
              XmlString += '<APID>';
              XmlString += APAppObj.Au_Pair__c;
              XmlString += '</APID>';
              XmlString += '<Filepath>';
              XmlString +=  APAppObj.Photo1__c;
              XmlString += '</Filepath>';
              XmlString += '</APFiles>';        
            }
            
            if(APAppObj.IsExist_Photo2__c == false )
            {
              XmlString += '<APFiles>';              
              XmlString += '<Id>';
              XmlString += APAppObj.Id;
              XmlString += '</Id>';
              XmlString += '<APID>';
              XmlString += APAppObj.Au_Pair__c;
              XmlString += '</APID>';
              XmlString += '<Filepath>';
              XmlString +=  APAppObj.Photo2__c;
              XmlString += '</Filepath>';
              XmlString += '</APFiles>';  
            }
            
            if(APAppObj.IsExist_Photo3__c == false )
            {
              XmlString += '<APFiles>';              
              XmlString += '<Id>';
              XmlString += APAppObj.Id;
              XmlString += '</Id>';
              XmlString += '<APID>';
              XmlString += APAppObj.Au_Pair__c;
              XmlString += '</APID>';
              XmlString += '<Filepath>';
              XmlString +=  APAppObj.Photo3__c;
              XmlString += '</Filepath>';
              XmlString += '</APFiles>';  
            }
            
            if(APAppObj.IsExist_Photo4__c == false )
            {
              XmlString += '<APFiles>';              
              XmlString += '<Id>';
              XmlString += APAppObj.Id;
              XmlString += '</Id>';
              XmlString += '<APID>';
              XmlString += APAppObj.Au_Pair__c;
              XmlString += '</APID>';
              XmlString += '<Filepath>';
              XmlString +=  APAppObj.Photo4__c;
              XmlString += '</Filepath>';
              XmlString += '</APFiles>';  
            }
      }
          //Close root Xml
          XmlString += '</APFilesData>';  
          System.debug('XML:' +XmlString);            
          System.debug('Entered1');  
          
           
            HttpRequest req = new HttpRequest();
          req.setEndpoint('http://Ip Address/Ajax.asmx');
           req.setMethod('POST');
           req.setHeader('Content-Type', 'text/xml; charset=utf-8');
           req.setHeader('SOAPAction', 'http://http://IP Address/GAPAPFiles');
          
          string b = '<?xml version="1.0" encoding="utf-8"?>';
          b += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
          b += '<soap:Body>';
          b += '<GAPAPFiles xmlns="http://IP Address">';
          b += '<xmlfiles>' + XmlString + '</xmlfiles>';
          b += '</GAPAPFiles>';
          b += '</soap:Body>';
          b += '</soap:Envelope>';
          
          req.setBody(b);
          
          Http http = new Http();
          HTTPResponse res = http.send(req);
        
          XmlStreamReader reader = new XmlStreamReader(res.getBody());
          while(reader.hasNext()) 
          {
            if (reader.getEventType() == XmlTag.START_ELEMENT) 
            {
              string FieldName = reader.getLocalName();
              reader.next();
              if (reader.getEventType() == XmlTag.CHARACTERS) 
              {
                // how do i get the three values in to a list or some thing so that i can update them into a different object.
              }
            }
            reader.next();
          }
        
      
      }

Hi ,

 

 I have created a Xml string type and passed it to a Apex call out method. The result of this method is a string too. Now i would want to convert the Result Xml string into a List object. please suggest.

 

public class APImageUpdates {
  public void APFilesMissing()
    {
      // Create list for Available Aupairs
      List<Contact> APContacts = [Select Id,AP_Status__c,RecordTypeId from Contact where AP_Status__c ='Available' AND contact.RecordTypeId ='012300000000AHhAAM' ];
      
      // Root of the Xml list
      string XmlString = '<APFilesData>';      
      for(Contact contact: APContacts) 
      {            
        for(AP_Application__c APAppObj: [Select Id,Au_Pair__c,AP_Folder_Name__c,Photo1__c,Photo2__c,Photo3__c,Photo4__c From AP_Application__c where Au_Pair__c =: contact.Id])
        {        
          if(APAppObj.IsExist_Photo1__c == false) 
          {  
            XmlString += '<APFiles>';
            XmlString += '<Apfoldername>';
            XmlString += APAppObj.AP_Folder_Name__c;
            XmlString += '</Apfoldername>';
            XmlString += '<Id>';
            XmlString += APAppObj.Id;
            XmlString += '</Id>';
            XmlString += '<APID>';
            XmlString += APAppObj.Au_Pair__c;
            XmlString += '</APID>';
            XmlString += '<FileUrl>';
            XmlString += APAppObj.Photo1__c;
            XmlString += '</FileUrl>';
            XmlString += '</APFiles>';    
                                     
          }
          
          if(APAppObj.IsExist_Photo2__c == false )
          {
            XmlString += '<APFiles>';
            XmlString += '<Apfoldername>';
            XmlString += APAppObj.AP_Folder_Name__c;
            XmlString += '</Apfoldername>';
            XmlString += '<Id>';
            XmlString += APAppObj.Id;
            XmlString += '</Id>';
            XmlString += '<APID>';
            XmlString += APAppObj.Au_Pair__c;
            XmlString += '</APID>';
            XmlString += '<FileUrl>';
            XmlString += APAppObj.Photo2__c;
            XmlString += '</FileUrl>';
            XmlString += '</APFiles>';  
          }
          
          if(APAppObj.IsExist_Photo3__c == false )
          {
            XmlString += '<APFiles>';
            XmlString += '<Apfoldername>';
            XmlString += APAppObj.AP_Folder_Name__c;
            XmlString += '</Apfoldername>';
            XmlString += '<Id>';
            XmlString += APAppObj.Id;
            XmlString += '</Id>';
            XmlString += '<APID>';
            XmlString += APAppObj.Au_Pair__c;
            XmlString += '</APID>';
            XmlString += '<FileUrl>';
            XmlString += APAppObj.Photo3__c;
            XmlString += '</FileUrl>';
            XmlString += '</APFiles>';  
          }
          
          if(APAppObj.IsExist_Photo4__c == false )
          {
            XmlString += '<APFiles>';
            XmlString += '<Apfoldername>';
            XmlString += APAppObj.AP_Folder_Name__c;
            XmlString += '</Apfoldername>';
            XmlString += '<Id>';
            XmlString += APAppObj.Id;
            XmlString += '</Id>';
            XmlString += '<APID>';
            XmlString += APAppObj.Au_Pair__c;
            XmlString += '</APID>';
            XmlString += '<FileUrl>';
            XmlString += APAppObj.Photo4__c;
            XmlString += '</FileUrl>';
            XmlString += '</APFiles>';  
          }
          
        }
      }
      
      //Close root Xml
      XmlString += '</APFilesData>';
      ServiceMethod(XmlString);
      }
   
   //Service Method  
   public static void ServiceMethod(string xml)
   {
     string ServiceResult = '';
     WebServiceOrg.AjaxSoap Service = new WebServiceOrg.AjaxSoap();
      ServiceResult = Service.GAPNetworkImages(xml);  
      Checkboxupdate(ServiceResult);   
   }
 
   public static void Checkboxupdate(string xml) 
   {

 List<AP_Application__c> APAppObj = new List<AP_Application__c>();
   }

 

 

I need to convert the resulting Xml and populate the results to List<AP_Application__c>. can someone please suggest

 

Thank you.
  

Hi,

 

Can the  List<AP_Application__c> APImagefiles  object be converted to a XML string to pass it to a .Net webservice.

I am trying to use the XmlStreamWriter class to build the Xml can anyone please suggest how to build the Xml with the list object. And also for each record in the List i would want to add the string value p for each record.

 

Thanks in Adavnce..

 

public class APImageUpdates {
  
  string Test;
  public void APImagesMissing()
  {
    string Photo1 = 'P1';
    string Photo2 = 'P2';
    string Photo3 = 'P3';
    string Photo4 = 'P4';
    List<Contact> APContacts = new List<Contact>();
    List<AP_Application__c> APImagefiles = new List<AP_Application__c>();    
    

    //Loop through Contacts for Available AuPairs 
    for(Contact contact: APContacts) 
    {
      system.debug('Entered the List');      
      if(contact.AP_Status__c =='Available' && contact.RecordTypeId =='012300000000AHhAAM')
      {              
        for(AP_Application__c APAppObj: [Select Id,Au_Pair__c,AP_Folder_Name__c From AP_Application__c where Au_Pair__c =: contact.Id])
        {
          if(APAppObj.IsExist_Photo1__c == false || APAppObj.IsExist_Photo2__c == false || APAppObj.IsExist_Photo3__c == false || APAppObj.IsExist_Photo4__c == false)
          {          
              APImagefiles.add(APAppObj);                          
          }
          update APImagefiles;
        }
      }
    }
  }
    
    public String getXml()
   {
       Xmlstreamwriter w = new Xmlstreamwriter();
       w.writeStartDocument(null, '1.0');
       w.writeProcessingInstruction('target', 'data');
      return 'Test';
    
   }   
    
     //Create the Stub
     AJAXOrg.AjaxSoap service = new AJAXOrg.AjaxSoap();       
     // Make the Web service call      
       String output = service.GAPNetworkImages(Test);
    
  

Hi,

 

Here below i have APImagefiles with records. Say 3 records have false for either of the photo and my list now has 3 records which i need to pass to web service callout. But if each of the record is missing a different photo number i need to pass the string value P1/P2/P3/P4. And also i need to pass total of 3 fields for each record ID,AP_Fodername__c, (string P1/P2/P3/P4)

 

Can you please suggest how i can pass these records

Cyrrently i am using a .net web service Method and it takes string types. 

 

}

public  class APImageUpdates {
  
  public void APImagesMissing()
  {
    
    string Photo1 = 'P1';
    string Photo2 = 'P2';
    string Photo3 = 'P3';
    string Photo4 = 'P4';
    List<Contact> APContacts = new List<Contact>();
    List<AP_Application__c> APImagefiles = new List<AP_Application__c>();    
    Map<String,String> APMissImgvalues = new Map<String,String>();

    //Loop through Contacts for Available AuPairs 
    for(Contact contact: APContacts) 
    {
      system.debug('Entered the List');      
      if(contact.AP_Status__c =='Available' && contact.RecordTypeId =='012300000000AHhAAM')
      {              
        for(AP_Application__c APAppObj: [Select Id,Au_Pair__c,AP_Folder_Name__c From AP_Application__c where Au_Pair__c =: contact.Id])
        {
          if(APAppObj.IsExist_Photo1__c == false || APAppObj.IsExist_Photo2__c == false || APAppObj.IsExist_Photo3__c == false || APAppObj.IsExist_Photo4__c == false)
          {          
              APImagefiles.add(APAppObj);
              APMissImgvalues.put(APAppObj.Id,APAppObj.AP_Folder_Name__c);
              
          }
          update APImagefiles;
        }
      }
    }
     System.debug('List of APs missing images:' +APImagefiles);  
     //Create the Stub
     AJAXOrg.AjaxSoap service = new AJAXOrg.AjaxSoap();       
     // Make the Web service call      
       String output = service.GAPNetworkImages();
    
  }

  • September 30, 2011
  • Like
  • 0

Hi,

 

Can lists be passed to a webservice methods. Or should they be passed as strings. If they should only be passed string whats the alternative to convert a list to a string.

 

please suggest.

 

Thank you

  • September 28, 2011
  • Like
  • 0

Hi,

 

I added the .net WSDL file to my Apex project and also added the endpoint URL in Salesforce remote settings.

So now in the following class below i have a list of objects APImageslist.

So the WSDL2Apex calss is called as AJAXOrg and has a method GAPNetworkInages().

This is the method i need to calla and pass the APImageslist to check for the images.

Can any one suggest what to be done after and how would i be able to connect the Wsdl2apex class.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

public  class APImageUpdates {
  
  public static void APImagesMissing()
  {
    List<Contact> Apcontact = new List<Contact>();  
      
    // Create a List to store the Au Pair contacts who are missing image files
    List<AP_Application__c> APImageslist = new List<AP_Application__c>();  
      
    //Loop through Contacts for Available AuPairs 
    for(Contact contact: Apcontact) 
    {
      system.debug('Entered the List');      
      if(contact.AP_Status__c =='Available' && contact.RecordTypeId =='012300000000AHhAAM')
      {              
        for(AP_Application__c APApp: [Select Id,Au_Pair__c,IsExist_Photo1__c,IsExist_Photo2__c,IsExist_Photo3__c,IsExist_Photo4__c From AP_Application__c where Au_Pair__c =: contact.Id])
        {
          if(APApp.IsExist_Photo1__c == false || APApp.IsExist_Photo2__c == false || APApp.IsExist_Photo3__c == false || APApp.IsExist_Photo4__c == false)
          {
            System.Debug('AP missing an Image with contact id' +contact.id);
              APImageslist.add(APApp);
          }
          update APImageslist;
        }
      }
    }
     System.debug('List of APs missing images:' +APImageslist);  
    // AJAXOrg.AjaxSoap service = new AJAXOrg.AjaxSoap();  
    
  }
}

 

  • September 23, 2011
  • Like
  • 0

I am trying to integrate my Apex code with a .Net webservice method.

My Apex class should query for a list of records and pass them to the .Net Webservice method.(How can i pass the list of records retrived). 

And the list is performed with a certain operation it should be passed back to Apex method for certain updates.

 

Can any one please provide me with an example for this integration with .Net web service.

 

Than you.

  • September 20, 2011
  • Like
  • 0

Hi,

 

I am trying to implement a Apex callout to a websrvice. For this i have so far performed the following procedure.

Generating the WSDL class and setting up Endpoint URL in the remote settings. So now i am stuck with how to call the service method from Apex and test if the connection is made.

 

URL: www.gapcentral.com/Ajax.asmx

Service method: GAPNetworkImages()

 

Thanks in Advance.

  • September 14, 2011
  • Like
  • 0

Hi,

 

I need to develop a class in which i should be able to verify, if certain files or folder does exist in our network server from SFDC apex code.

 

so its like Apex code --> Files on our server(checking if they exisit)--> and update exisiting value in SFDC.

 

how do i connect to the server.

 

Any help would be greatly appreciated.

 

Thank you.

 

I have marked in red the lines of code where it sayd 0% coverage. please suggest.

public class HFSendSurveyClass { public void SendSurvey() { //String hfsurvey; Date hfsurvey; //Get the most recently created config object. Config_Object__c config = [Select HFSurveyCode__c, SurveyDate__C, SOQL_Query__C from Config_Object__C where Name ='HostFamily_Survey' limit 1 ]; List<Opportunity> oppList = Database.query(config.SOQL_Query__c); //System.debug('Bharath:' +opplist); List<Account> accList = new List<Account>(); //System.debug('Bharath:' +accList); try { for(Opportunity opp:oppList) { if(opp.AccountId!= null) { Account acc = opp.Account; if(opp.Survey_Opp_Id_Match__c== 'No') { System.debug('Bharath date: '+config.SurveyDate__c); if(String.valueOf(config.SurveyDate__c) != Null) { if(String.valueOf(config.SurveyDate__c).contains('+')) { string s = String.valueOf(config.SurveyDate__c); string intvalue = adddaystostringvalue(s); hfsurvey = Date.today().addDays(integer.valueOf(intvalue)); } else { hfsurvey = Date.Today(); } } string oppcode= opp.Id; acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); acc.Survey_Dt__c = hfsurvey; acc.Survey_Opp_Id__c = oppcode.subString(0,15); System.debug('Bharath account123: '+acc.Survey_Code__c+' '+String.valueOf(config.HFSurveyCode__c)); } else if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c)) { System.debug('Bharath date2: '+config.SurveyDate__c); if(String.valueOf(config.SurveyDate__c) != Null) { if(String.valueOf(config.SurveyDate__c).contains('+')) { string s = String.valueOf(config.SurveyDate__c); string intvalue = adddaystostringvalue(s); hfsurvey = Date.today().addDays(integer.valueOf(intvalue)); } else { hfsurvey = Date.Today(); } } string oppcode= opp.Id; acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); acc.Survey_Dt__c = hfsurvey; acc.Survey_Opp_Id__c = oppcode.subString(0,15); } accList.add(acc); } } update accList; } catch (Exception e) { System.debug(e.getMessage()); } } private String adddaystostringvalue (string surveydays) { if(surveydays != null) surveydays = surveydays.substring(surveydays.indexOf('+')+ 1).trim(); return surveydays; }

 

TEst Class


	@istest

private class HFSendSurveyTestClass {


     static testMethod void testSendSurvey(){
        String query = 'Select o.Id,o.Survey_Opp_Id_Match__c ,o.Account.Name From Opportunity o where o.StageName=&#Active&# AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60 AND o.Survey_Opp_Id_Match__c=&#No&# limit 1';
        Config_Object__c config = new Config_Object__c();
        config.HFSurveyCode__c ='HF1MoArv';
        config.SurveyDate__c = 'Today';
        config.SOQL_Query__c = query;
        config.Name = 'HostFamily_Survey';
        
        Opportunity opp = new Opportunity();
        Account acc = new Account();
        
        acc.Name = 'TestSurvey';
        acc.Survey_Code__c='HFReferal';
        acc.Survey_Dt__c = Date.today();
        acc.Survey_Opp_Id__c = opp.Id;
        System.debug('Bharath acc:' +acc);
        Insert acc;
        
        opp.Name = acc.Name;
        opp.AccountId = acc.Id;
        opp.StageName = 'Active';
        Date placedate = Date.newInstance(2011,03,01);
        opp.Placmnt_Start_Date_Arrive__c = placedate;
        opp.CloseDate = Date.today();
        //opp.Account = acc;
        //opp.Survey_Opp_Id_Match__c = 'Yes';
        //opp.Survey_Opp_Id_Match__c == 'No';
        System.debug('Bharath opp:' +opp);
        Insert opp;
        
        // List<Opportunity> o = [Select Name,AccountId,StageName,Placmnt_Start_Date_Arrive__c FROM Opportunity where Name = 'TestSurvey'];
        //List<Account> a = [Select Name,Survey_Code__c,Survey_Opp_Id__c,Survey_Dt__c  FROM Account where Name = 'TestSurvey'];
        
        HFSendSurveyClass sv = new HFSendSurveyClass();
        sv.SendSurvey(); 
     }
     
     //public static testMethod void testadddaystostringvalue()
     //{
     // string x = string.valueOf('Today+2');
     // HFSendSurveyClass s = new HFSendSurveyClass();
     // s.adddaystostringvalue(x); 
        //adddaystostringvalue(x);
     //}
     
     
}

 

 

If i run my test class individually i am just able to see 22% as code coverage. And my original class does not have any code coverage. 

 

Class 

 

public class HFSendSurveyClass {
    public void SendSurvey()
    {
        
      //String hfsurvey;
        Date hfsurvey;        
      //Get the most recently created config object.
     Config_Object__c config = [Select HFSurveyCode__c, SurveyDate__C, SOQL_Query__C from Config_Object__C 
                                where Name ='HostFamily_Survey' limit 1 ];
       
     List<Opportunity> oppList = Database.query(config.SOQL_Query__c); 
     List<Account> accList = new List<Account>(); 
                 
   for(Opportunity opp:oppList)
           
         {
            if(opp.AccountId!= null)
                {
                      Account acc = opp.Account; 
                      if(opp.Survey_Opp_Id_Match__c== 'No')
                          {
                            if(String.valueOf(config.SurveyDate__c) == 'Today')
                              {
                               hfsurvey = Date.Today();
                              }
                          else if(String.valueOf(config.SurveyDate__c).contains('+'))
                              {
                                string s = String.valueOf(config.SurveyDate__c);
                                string intvalue = adddaystostringvalue(s);
                                hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                              }
                              
                         string oppcode= opp.Id;
                         acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                         acc.Survey_Dt__c = hfsurvey;
                         acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                         System.Debug(acc.Survey_Code__c);
                         System.Debug(acc.Survey_Dt__c );
                         System.Debug(acc.Survey_Opp_Id__c );
                           }
                                     
                    else if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c))    
                        {                    
                            if(String.valueOf(config.SurveyDate__c) == 'Today')
                              {
                               hfsurvey = Date.Today();
                              }
                             else if(String.valueOf(config.SurveyDate__c).contains('+'))
                              {
                                string s = String.valueOf(config.SurveyDate__c);
                                string intvalue = adddaystostringvalue(s);
                                hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                              }
                             string oppcode= opp.Id;
                             acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                             acc.Survey_Dt__c = hfsurvey;
                             acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                             System.Debug(acc.Survey_Code__c);
                             System.Debug(acc.Survey_Dt__c );
                             System.Debug(acc.Survey_Opp_Id__c );
                       } 
                  
                 accList.add(acc);                
                }
             }
       update accList;                            
     }    
     
     private String adddaystostringvalue (string surveydays)
     {
        if(surveydays != null)
            surveydays = surveydays.substring(surveydays.indexOf('+')+ 1).trim(); 
            System.Debug(surveydays); 
            return surveydays;  
          
        
     }
}
Test class:
public class HFSendSurveyTestClass {
     static testMethod void SendSurvey()
     {
      Date hfsurvey;  
      // Get the most recently created config object.
         Config_Object__c config = new Config_Object__c();
         config.Name = 'HostFamily_Survey';
         config.HFSurveyCode__c = 'HF1MoArv';
         config.SurveyDate__c= 'Today+1';
         config.SOQL_query__c = string.ValueOf('Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name From Opportunity o where o.StageName= &#Active&# AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60  AND o.Survey_Opp_Id_Match__c= &#No&# limit 1');
         insert config;              
         
          Account acc = new Account();
          acc.Name = 'Testsurvey';
          acc.Survey_Code__c = 'HFReferal';
          acc.Survey_Dt__c= Date.today();                 
          insert acc;  
        
         Opportunity opp= new Opportunity();
         //opp.RecordType='HF FT Placemnt Rel 2';
         opp.Name='Testsurvey';
         opp.AccountId = acc.id; 
         opp.StageName='Active';       
         opp.Placmnt_Start_Date_Arrive__c = Date.newInstance(2011, 02, 14); 
         opp.CloseDate=Date.Today();   
         //opp.Account.Survey_Opp_Id__c = opp.id;   
         insert opp;    
         
         config = [Select HFSurveyCode__c,SurveyDate__c,SOQL_Query__C from Config_Object__C where Name ='HostFamily_Survey' limit 1];
         List<Opportunity> oppList = [Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name From Opportunity o where o.StageName= 'Active' AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60  AND o.Survey_Opp_Id_Match__c= 'No' limit 1];
         List<Account> accList = [Select Name,Survey_Code__c,Survey_Dt__c,Survey_Opp_Id__c from Account Where Name ='Testsurvey' And Survey_Code__c = 'HFReferal' limit 1];      
         
          for(Opportunity opps:oppList)  
         {
                if(opp.AccountId!= null)
                {
                      Account accs = opp.Account;                        
                      
          if(opp.Survey_Opp_Id_Match__c== 'No')
                  {
                    if(String.valueOf(config.SurveyDate__c) == 'Today')
                      {
                       hfsurvey = Date.Today();
                      }
               else if(String.valueOf(config.SurveyDate__c).contains('+'))
                      {
                        string s = String.valueOf(config.SurveyDate__c);
                        string intvalue = '1';
                        hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                      }
                         string oppcode= opp.Id;
                         acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                         acc.Survey_Dt__c = hfsurvey;
                         acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                  }
                            
                                     
             else if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c))    
                   {
                    
                    if(String.valueOf(config.SurveyDate__c) == 'Today')
                      {
                       hfsurvey = Date.Today();
                      }
                 else if(String.valueOf(config.SurveyDate__c).contains('+'))
                      {
                        string s = String.valueOf(config.SurveyDate__c);
                        string intvalue = '1';
                        hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                      }
                         string oppcode= opp.Id;
                         acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                         acc.Survey_Dt__c = hfsurvey;
                         acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                   } 
                 //accList.add(accs);
                 }
            }
         // update accList;  
        
        
        System.assertEquals(config.HFSurveyCode__c,acc.Survey_Code__c);
        System.assertEquals(hfsurvey,acc.Survey_Dt__c);
        System.assertEquals(opp.Id,acc.Survey_Opp_Id__c);
        System.Debug(acc.Survey_Code__c);
        System.Debug(acc.Survey_Dt__c);
        
     }
     
}

 

 

Can some one please susggest to increase my code coverage.

 

Thanks in Advance.

Config ObjectHi, this is my custom object. i need to pull the survey date value from here to my class where i need to update a field. the code is below the object. please suggest. Config Object HostFamily_Survey
 
Config Object Detail
Survey_NameHostFamily_SurveyOwner
Used In..Survey Code  
HF Survey CodeHF1MoArv  
SOQL_QuerySelect o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c,
o.Survey_Opp_Id_Match__c ,
o.Account.Name
From Opportunity o
where o.StageName='Active'
AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30
AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60
AND o.Survey_Opp_Id_Match__c='No'
  
SurveyDateToday()  
Created By2/7/2011 11:31 AMLast Modified By

3/28/2011 1:06 PM

 

 

 

public class HFSendSurveyClass {
    public void SendSurvey()
    {
        
        Date hfsurvey;        
      //Get the most recently created config object.
     Config_Object__c config = [Select HFSurveyCode__c, SurveyDate__C, SOQL_Query__C from Config_Object__C
                                where Name ='HostFamily_Survey'];
       
     List<Opportunity> oppList = Database.query(config.SOQL_Query__c);        
     
     List<Account> accList = new List<Account>();             
           for(Opportunity opp:oppList)
             {
                if(opp.AccountId!= null)
                {
                  Account acc = opp.Account;
                  hfsurvey = Date.valueOf(config.SurveyDate__c);
                  if(opp.Survey_Opp_Id_Match__c== 'No')
                  {
                     string oppcode= opp.Id;
                     acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c);
                     acc.Survey_Dt__c = hfsurvey;
                     acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                  }
                                     
            else  if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c))    
                   {
                     string oppcode= opp.Id;
                     acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c);
                     acc.Survey_Dt__c =  hfsurvey;
                     acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                   }
                  
                 accList.add(acc);
                 //System.assertEquals(acc.Survey_Dt__c,Date.valueOf(config.SurveyDate__c) ) ;
                }
             }
       update accList;                            
     }    
}

 

 

 

 

 

The marked field is where i should be update the value frim the custome object. The surveydate in custom object is string type and the Survey_Dt__c field is a date field. and should be able to add days or change the date so i want to pass the line of code for date as a string and pick it up in my class to update it with that date.

 

Please suggest thanks in advance.

 

 


 

 

Hi, I have Scheduler class which is not initiating any other class but has a static method within. I had to build this class such a way as i had to make a apex call out and which needs to static. So my scheduler class works fine but i need a head start on how i can test the rest of the lines of code please check below for code and help me give a head start. /*The scheduler class fires hourly for the AP Files*/ global class APFiles_ScheduledHourlyRun implements Schedulable { global void execute(SchedulableContext sc) { APFilesMissing(); } @future(callout=true) public static void APFilesMissing() { // Exception log to capture various kind of errors as unable to make callouts, bad data or read time out issues. List errors = new List(); Datetime RuntimeCode = Datetime.newInstance(date.today(),time.newInstance(1, 11, 11, 0)); try { string ServiceResult = ''; // Creates list for Available Aupairs List APFiles = [Select a.Id ,a.Au_Pair__c,a.AP_Folder_Name__c, a.Photo4__c, a.Photo3__c, a.Photo2__c, a.Photo1__c, a.IsExist_Photo4__c, a.IsExist_Photo3__c, a.IsExist_Photo2__c, a.IsExist_Photo1__c,a.Au_Pair__r.Id,a.Au_Pair__r.AP_Status__c,a.Au_Pair__r.Record_Type_Name__c From AP_Application__c a where a.Au_Pair__r.AP_Status__c ='Available' AND a.Au_Pair__r.Record_Type_Name__c= 'Au Pair']; // Root of Xml string string XmlString = ''; //Create Xml record element for every APPhoto file with IsPhotoExist as false for(AP_Application__c APAppObj: APFiles) { if(APAppObj.IsExist_Photo1__c == false) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo1__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo2__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo2__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo3__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo3__c+''; XmlString += ''; } if(APAppObj.IsExist_Photo4__c == false ) { XmlString += ''; XmlString += ''+APAppObj.Id+''; XmlString += ''+APAppObj.Au_Pair__c+''; XmlString += ''+APAppObj.Photo4__c+''; XmlString += ''; } } //Close root Xml XmlString += ''; System.debug('XML:' +XmlString); // Create WSDL Stub for Call out GAPOrg.AjaxSoap servicestub = new GAPOrg.AjaxSoap(); servicestub.timeout_x = 9000; ServiceResult = servicestub.GAPAPFiles(XmlString); //System.debug('XmlResultfromService:' +xmldata); //Retrive the values from Xml using DOM class List Files = new List(); Dom.Document docx = new Dom.Document(); docx.load(ServiceResult); Dom.Xmlnode xroot = docx.getRootElement(); Dom.Xmlnode[] xrec = xroot.getChildElements(); for(Dom.Xmlnode child : xrec) { Files__c file = new Files__c(); for(Dom.Xmlnode node : child.getchildren()) { if(node.getName() == 'ApplicationId') { //system.debug('ApplicationId:' +node.gettext()); file.AP_Application__c = node.gettext(); } if(node.getName() == 'APID') { //system.debug('APID:' +node.gettext()); file.Contact__c = node.gettext(); } if(node.getName() == 'Filepath') { String[] path = node.gettext().split('/'); string filepath = +path[4]+'/'+path[5]+'/'+path[6]+'/'+path[7]; system.debug('Filepath:'+path[4]+'/'+path[5]+'/'+path[6]+'/'+path[7]); //system.debug('Filepath:' +node.gettext()); file.Path__c = filepath; } } Files.add(file); system.debug(File); } insert Files; } catch (Exception e) { Exception_Log__c ex = new Exception_Log__c(); ex.Exception_Code__c =''; ex.Error_Message__c = e.getMessage(); errors.add(ex); System.debug(e.getMessage()); } List nice = BusinessExceptionServices.SaveLogEntries(null,errors); errors.clear(); } } Thank in advance!

Hi ,

System.DmlException: Upsert failed. First exception on row 0 with id a1WV00000001HBKMA2; first error: MISSING_ARGUMENT, External_ID__c not specified: []

I have my upsert opration failing. Can any one please suggest whats wrong in the below code and how help fix the code.

public with sharing class APImageUpdatesGlobal {
    public void APFilesMissingGlobal()
        {
          string ServiceResult = '';  
          System.debug('Entered!');
      
          // Create list for Available Aupairs
          List<AP_Application__c> APFiles = [Select a.Photo4__c, a.Photo3__c, a.Photo2__c, a.Photo1__c, a.Id, a.External_ID_Photo4__c, a.External_ID_Photo3__c, a.External_ID_Photo2__c, a.External_ID_Photo1__c, a.Au_Pair__c From AP_Application__c a where a.Au_Pair__r.AP_Status__c ='Available' AND a.Au_Pair__r.Record_Type_Name__c= 'Au Pair'];      
          
          string XmlString = '<FilesData>';                
          for(AP_Application__c APFile: APFiles)
            {    
              XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo1__c+'</Path>';  
              XmlString += '<External_ID>'+APFile.External_ID_Photo1__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';  
              XmlString += '</APFiles>';    
              
                XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo2__c+'</Path>';
              XmlString += '<External_ID>'+APFile.External_ID_Photo2__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';
              XmlString += '</APFiles>';  
              
              XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo3__c+'</Path>';
              XmlString += '<External_ID>'+APFile.External_ID_Photo3__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';
              XmlString += '</APFiles>';  
              
              XmlString += '<APFiles>';
              XmlString += '<ApplicationId>'+APFile.Id+'</ApplicationId>';
              XmlString += '<APID>'+APFile.Au_Pair__c+'</APID>';
              XmlString += '<Path>'+APFile.Photo4__c+'</Path>';  
              XmlString += '<External_ID>'+APFile.External_ID_Photo4__c+'</External_ID>';
              XmlString += '<Inactive_Dt></Inactive_Dt>';                
              XmlString += '</APFiles>';            
            }
              //Close root Xml
            XmlString += '</FilesData>';         
            GAPOrg.AjaxSoap Servicestub = new GAPOrg.AjaxSoap();
            ServiceResult = Servicestub.GAPAPFilesGlobalRun(XmlString);          
            Dom.Document docx = new Dom.Document();
              docx.load(ServiceResult);
              Dom.Xmlnode root = docx.getRootElement();
              List<Files__c> upsertfiles = new List<Files__c>(); 
              for(Dom.Xmlnode child : root.getChildElements())    {             
               Files__c file = null;           
               for(Dom.Xmlnode node : child.getChildElements())      {                  
                   if(node.getName() == 'External_ID') {                    
                     string str = node.getText();               
                          if( str != ''){
                             file = new Files__c();        file = [Select f.Path__c, f.Inactive_Date__c, f.Id, f.External_ID__c, f.Contact__c, f.AP_Application__c From Files__c f where f.External_ID__c =: node.gettext() limit 1 ];
                     }
                 } 
                 else if(node.getName() == 'Inactive_Dt')
                 {
                   if(file != null) {
                     if(node.getText() != ' ')
                     {
                      String[] stringDate = node.gettext().split('/');                     
                       Integer m =  Integer.valueOf(stringDate[0]);
                       Integer d = Integer.valueOf(stringDate[1]);
                       Integer y = Integer.valueOf(stringDate[2]);  
                      file.Inactive_Date__c = date.newinstance(y,m,d);                   
                     }
                   }
                 }
               }
               if (file == null) {  
               for(Dom.Xmlnode node : child.getChildElements())
               {
                  string str = node.getName();                 
                  file = new Files__c();                     
                 if(str == 'ApplicationId')
                 {    file.AP_Application__c = node.gettext();     }
                 else if(str == 'APID')
                 {  file.Contact__c = node.gettext();    }
                 else if(str == 'Path')
                 {   file.Path__c = node.gettext();   }
                 else if(str == 'Inactive_Dt')
                {
                 if(str != ' ')
                   {
                    String[] stringDate = node.gettext().split('/');                  
                     Integer m =  Integer.valueOf(stringDate[0]);
                     Integer d = Integer.valueOf(stringDate[1]);
                     Integer y = Integer.valueOf(stringDate[2]);  
                    file.Inactive_Date__c = date.newinstance(y,m,d);
                   }
                 }
               }
           }      
          upsertfiles.add(file);   
          file =null;                    
        }         
        try {   upsert upsertfiles External_ID__c;      }
        
          catch (DmlException e) {
                System.debug(e.getMessage());
           }    
     }
}

Hi 

 

I am having the above error and i understand that its beacuse i am updating my object over and over . As the if contion is true i am updating again and again. Can anyone please suggest a  work around as how i can have updates even after if conditions.

trigger APFileUpdates on Files__c (after insert) {

    if(trigger.isInsert)
    {  
      System.debug('Trigger is fired.');
      List<Files__c> APFiles  = trigger.new;
      List<AP_Application__c> UpdateAPApp = new List<AP_Application__c>();
      //List<Files__c> processList= new List<Files__c>();       
        set<String> zips = new set<String>();
      string P1 = 'Photo1.jpg';
      string P2 = 'Photo2.jpg';
      string P3 = 'Photo3.jpg';
      string P4 = 'Photo4.jpg';      
      if(trigger.new != null && trigger.new.size() > 0)
      {
        System.debug('Trigger is fired.');
        for (Files__c file: APFiles)
        {  
          string path = file.Path__c;                      
          AP_Application__c App = [Select a.Id,a.IsExist_Photo1__c, a.IsExist_Photo2__c, a.IsExist_Photo3__c, a.IsExist_Photo4__c, a.Au_Pair__c,External_ID_Photo1__c From AP_Application__c a where id =: file.AP_Application__c ];             
          if(path.contains(p1))
          {
            App.IsExist_Photo1__c = true;
            App.External_ID_Photo1__c = file.External_ID__c;
            UpdateAPApp.add(App);  
          }          
          System.debug('APResultApplication:' +App);                      
          
          if(path.contains(p2))
          {              
            App.IsExist_Photo2__c = true;
            App.External_ID_Photo2__c = file.External_ID__c;
            UpdateAPApp.add(App);                        
          }
          if(path.contains(p3))
          {            
            App.IsExist_Photo3__c = true;
            App.External_ID_Photo3__c = file.External_ID__c;
            UpdateAPApp.add(App);                        
          }
          if(path.contains(p4))
          {             
            App.IsExist_Photo4__c = true;
            App.External_ID_Photo4__c = file.External_ID__c;
            UpdateAPApp.add(App);                        
          }
                          
        }
        update UpdateAPApp;
      }
      
    }
}

Thank you.

Hi,

 

When i make a call to an external web service from an apex class, i got the following error:

 

System.CalloutException: IO Exception: Read timed out 

 

The call works fine with the test environnement where the web service is exposed. However wiht their production environment, the error above is thrown. Is it a problem of mass data or security (proxy) ?

 

Could you help please ?

 

All the best,

 

Anzar.

Hi, I am trying to make a Apex callout but facing various errors in it. one of them below is 

 

System.CalloutException: IO Exception: java.security.cert.CertificateException: No subject alternative names matching IP address xx.xx.xx.xxx found

 

Any suggestion or help would be greatly appreciated.

 

Thank you,

Hi,

 

Can lists be passed to a webservice methods. Or should they be passed as strings. If they should only be passed string whats the alternative to convert a list to a string.

 

please suggest.

 

Thank you

  • September 28, 2011
  • Like
  • 0

Hi,

 

I added the .net WSDL file to my Apex project and also added the endpoint URL in Salesforce remote settings.

So now in the following class below i have a list of objects APImageslist.

So the WSDL2Apex calss is called as AJAXOrg and has a method GAPNetworkInages().

This is the method i need to calla and pass the APImageslist to check for the images.

Can any one suggest what to be done after and how would i be able to connect the Wsdl2apex class.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

public  class APImageUpdates {
  
  public static void APImagesMissing()
  {
    List<Contact> Apcontact = new List<Contact>();  
      
    // Create a List to store the Au Pair contacts who are missing image files
    List<AP_Application__c> APImageslist = new List<AP_Application__c>();  
      
    //Loop through Contacts for Available AuPairs 
    for(Contact contact: Apcontact) 
    {
      system.debug('Entered the List');      
      if(contact.AP_Status__c =='Available' && contact.RecordTypeId =='012300000000AHhAAM')
      {              
        for(AP_Application__c APApp: [Select Id,Au_Pair__c,IsExist_Photo1__c,IsExist_Photo2__c,IsExist_Photo3__c,IsExist_Photo4__c From AP_Application__c where Au_Pair__c =: contact.Id])
        {
          if(APApp.IsExist_Photo1__c == false || APApp.IsExist_Photo2__c == false || APApp.IsExist_Photo3__c == false || APApp.IsExist_Photo4__c == false)
          {
            System.Debug('AP missing an Image with contact id' +contact.id);
              APImageslist.add(APApp);
          }
          update APImageslist;
        }
      }
    }
     System.debug('List of APs missing images:' +APImageslist);  
    // AJAXOrg.AjaxSoap service = new AJAXOrg.AjaxSoap();  
    
  }
}

 

  • September 23, 2011
  • Like
  • 0

Hi,

 

I am trying to implement a Apex callout to a websrvice. For this i have so far performed the following procedure.

Generating the WSDL class and setting up Endpoint URL in the remote settings. So now i am stuck with how to call the service method from Apex and test if the connection is made.

 

URL: www.gapcentral.com/Ajax.asmx

Service method: GAPNetworkImages()

 

Thanks in Advance.

  • September 14, 2011
  • Like
  • 0

 

I have marked in red the lines of code where it sayd 0% coverage. please suggest.

public class HFSendSurveyClass { public void SendSurvey() { //String hfsurvey; Date hfsurvey; //Get the most recently created config object. Config_Object__c config = [Select HFSurveyCode__c, SurveyDate__C, SOQL_Query__C from Config_Object__C where Name ='HostFamily_Survey' limit 1 ]; List<Opportunity> oppList = Database.query(config.SOQL_Query__c); //System.debug('Bharath:' +opplist); List<Account> accList = new List<Account>(); //System.debug('Bharath:' +accList); try { for(Opportunity opp:oppList) { if(opp.AccountId!= null) { Account acc = opp.Account; if(opp.Survey_Opp_Id_Match__c== 'No') { System.debug('Bharath date: '+config.SurveyDate__c); if(String.valueOf(config.SurveyDate__c) != Null) { if(String.valueOf(config.SurveyDate__c).contains('+')) { string s = String.valueOf(config.SurveyDate__c); string intvalue = adddaystostringvalue(s); hfsurvey = Date.today().addDays(integer.valueOf(intvalue)); } else { hfsurvey = Date.Today(); } } string oppcode= opp.Id; acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); acc.Survey_Dt__c = hfsurvey; acc.Survey_Opp_Id__c = oppcode.subString(0,15); System.debug('Bharath account123: '+acc.Survey_Code__c+' '+String.valueOf(config.HFSurveyCode__c)); } else if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c)) { System.debug('Bharath date2: '+config.SurveyDate__c); if(String.valueOf(config.SurveyDate__c) != Null) { if(String.valueOf(config.SurveyDate__c).contains('+')) { string s = String.valueOf(config.SurveyDate__c); string intvalue = adddaystostringvalue(s); hfsurvey = Date.today().addDays(integer.valueOf(intvalue)); } else { hfsurvey = Date.Today(); } } string oppcode= opp.Id; acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); acc.Survey_Dt__c = hfsurvey; acc.Survey_Opp_Id__c = oppcode.subString(0,15); } accList.add(acc); } } update accList; } catch (Exception e) { System.debug(e.getMessage()); } } private String adddaystostringvalue (string surveydays) { if(surveydays != null) surveydays = surveydays.substring(surveydays.indexOf('+')+ 1).trim(); return surveydays; }

 

TEst Class


	@istest

private class HFSendSurveyTestClass {


     static testMethod void testSendSurvey(){
        String query = 'Select o.Id,o.Survey_Opp_Id_Match__c ,o.Account.Name From Opportunity o where o.StageName=&#Active&# AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60 AND o.Survey_Opp_Id_Match__c=&#No&# limit 1';
        Config_Object__c config = new Config_Object__c();
        config.HFSurveyCode__c ='HF1MoArv';
        config.SurveyDate__c = 'Today';
        config.SOQL_Query__c = query;
        config.Name = 'HostFamily_Survey';
        
        Opportunity opp = new Opportunity();
        Account acc = new Account();
        
        acc.Name = 'TestSurvey';
        acc.Survey_Code__c='HFReferal';
        acc.Survey_Dt__c = Date.today();
        acc.Survey_Opp_Id__c = opp.Id;
        System.debug('Bharath acc:' +acc);
        Insert acc;
        
        opp.Name = acc.Name;
        opp.AccountId = acc.Id;
        opp.StageName = 'Active';
        Date placedate = Date.newInstance(2011,03,01);
        opp.Placmnt_Start_Date_Arrive__c = placedate;
        opp.CloseDate = Date.today();
        //opp.Account = acc;
        //opp.Survey_Opp_Id_Match__c = 'Yes';
        //opp.Survey_Opp_Id_Match__c == 'No';
        System.debug('Bharath opp:' +opp);
        Insert opp;
        
        // List<Opportunity> o = [Select Name,AccountId,StageName,Placmnt_Start_Date_Arrive__c FROM Opportunity where Name = 'TestSurvey'];
        //List<Account> a = [Select Name,Survey_Code__c,Survey_Opp_Id__c,Survey_Dt__c  FROM Account where Name = 'TestSurvey'];
        
        HFSendSurveyClass sv = new HFSendSurveyClass();
        sv.SendSurvey(); 
     }
     
     //public static testMethod void testadddaystostringvalue()
     //{
     // string x = string.valueOf('Today+2');
     // HFSendSurveyClass s = new HFSendSurveyClass();
     // s.adddaystostringvalue(x); 
        //adddaystostringvalue(x);
     //}
     
     
}

 

 

If i run my test class individually i am just able to see 22% as code coverage. And my original class does not have any code coverage. 

 

Class 

 

public class HFSendSurveyClass {
    public void SendSurvey()
    {
        
      //String hfsurvey;
        Date hfsurvey;        
      //Get the most recently created config object.
     Config_Object__c config = [Select HFSurveyCode__c, SurveyDate__C, SOQL_Query__C from Config_Object__C 
                                where Name ='HostFamily_Survey' limit 1 ];
       
     List<Opportunity> oppList = Database.query(config.SOQL_Query__c); 
     List<Account> accList = new List<Account>(); 
                 
   for(Opportunity opp:oppList)
           
         {
            if(opp.AccountId!= null)
                {
                      Account acc = opp.Account; 
                      if(opp.Survey_Opp_Id_Match__c== 'No')
                          {
                            if(String.valueOf(config.SurveyDate__c) == 'Today')
                              {
                               hfsurvey = Date.Today();
                              }
                          else if(String.valueOf(config.SurveyDate__c).contains('+'))
                              {
                                string s = String.valueOf(config.SurveyDate__c);
                                string intvalue = adddaystostringvalue(s);
                                hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                              }
                              
                         string oppcode= opp.Id;
                         acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                         acc.Survey_Dt__c = hfsurvey;
                         acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                         System.Debug(acc.Survey_Code__c);
                         System.Debug(acc.Survey_Dt__c );
                         System.Debug(acc.Survey_Opp_Id__c );
                           }
                                     
                    else if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c))    
                        {                    
                            if(String.valueOf(config.SurveyDate__c) == 'Today')
                              {
                               hfsurvey = Date.Today();
                              }
                             else if(String.valueOf(config.SurveyDate__c).contains('+'))
                              {
                                string s = String.valueOf(config.SurveyDate__c);
                                string intvalue = adddaystostringvalue(s);
                                hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                              }
                             string oppcode= opp.Id;
                             acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                             acc.Survey_Dt__c = hfsurvey;
                             acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                             System.Debug(acc.Survey_Code__c);
                             System.Debug(acc.Survey_Dt__c );
                             System.Debug(acc.Survey_Opp_Id__c );
                       } 
                  
                 accList.add(acc);                
                }
             }
       update accList;                            
     }    
     
     private String adddaystostringvalue (string surveydays)
     {
        if(surveydays != null)
            surveydays = surveydays.substring(surveydays.indexOf('+')+ 1).trim(); 
            System.Debug(surveydays); 
            return surveydays;  
          
        
     }
}
Test class:
public class HFSendSurveyTestClass {
     static testMethod void SendSurvey()
     {
      Date hfsurvey;  
      // Get the most recently created config object.
         Config_Object__c config = new Config_Object__c();
         config.Name = 'HostFamily_Survey';
         config.HFSurveyCode__c = 'HF1MoArv';
         config.SurveyDate__c= 'Today+1';
         config.SOQL_query__c = string.ValueOf('Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name From Opportunity o where o.StageName= &#Active&# AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60  AND o.Survey_Opp_Id_Match__c= &#No&# limit 1');
         insert config;              
         
          Account acc = new Account();
          acc.Name = 'Testsurvey';
          acc.Survey_Code__c = 'HFReferal';
          acc.Survey_Dt__c= Date.today();                 
          insert acc;  
        
         Opportunity opp= new Opportunity();
         //opp.RecordType='HF FT Placemnt Rel 2';
         opp.Name='Testsurvey';
         opp.AccountId = acc.id; 
         opp.StageName='Active';       
         opp.Placmnt_Start_Date_Arrive__c = Date.newInstance(2011, 02, 14); 
         opp.CloseDate=Date.Today();   
         //opp.Account.Survey_Opp_Id__c = opp.id;   
         insert opp;    
         
         config = [Select HFSurveyCode__c,SurveyDate__c,SOQL_Query__C from Config_Object__C where Name ='HostFamily_Survey' limit 1];
         List<Opportunity> oppList = [Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name From Opportunity o where o.StageName= 'Active' AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60  AND o.Survey_Opp_Id_Match__c= 'No' limit 1];
         List<Account> accList = [Select Name,Survey_Code__c,Survey_Dt__c,Survey_Opp_Id__c from Account Where Name ='Testsurvey' And Survey_Code__c = 'HFReferal' limit 1];      
         
          for(Opportunity opps:oppList)  
         {
                if(opp.AccountId!= null)
                {
                      Account accs = opp.Account;                        
                      
          if(opp.Survey_Opp_Id_Match__c== 'No')
                  {
                    if(String.valueOf(config.SurveyDate__c) == 'Today')
                      {
                       hfsurvey = Date.Today();
                      }
               else if(String.valueOf(config.SurveyDate__c).contains('+'))
                      {
                        string s = String.valueOf(config.SurveyDate__c);
                        string intvalue = '1';
                        hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                      }
                         string oppcode= opp.Id;
                         acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                         acc.Survey_Dt__c = hfsurvey;
                         acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                  }
                            
                                     
             else if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c))    
                   {
                    
                    if(String.valueOf(config.SurveyDate__c) == 'Today')
                      {
                       hfsurvey = Date.Today();
                      }
                 else if(String.valueOf(config.SurveyDate__c).contains('+'))
                      {
                        string s = String.valueOf(config.SurveyDate__c);
                        string intvalue = '1';
                        hfsurvey = Date.today().addDays(integer.valueOf(intvalue));
                      }
                         string oppcode= opp.Id;
                         acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                         acc.Survey_Dt__c = hfsurvey;
                         acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                   } 
                 //accList.add(accs);
                 }
            }
         // update accList;  
        
        
        System.assertEquals(config.HFSurveyCode__c,acc.Survey_Code__c);
        System.assertEquals(hfsurvey,acc.Survey_Dt__c);
        System.assertEquals(opp.Id,acc.Survey_Opp_Id__c);
        System.Debug(acc.Survey_Code__c);
        System.Debug(acc.Survey_Dt__c);
        
     }
     
}

 

 

Can some one please susggest to increase my code coverage.

 

Thanks in Advance.

Hi,

 

I have a test class written for my apex class. But i am not sure if correct. In the sandbox if RUN TEST for the class itself it says the following

Apex Test Result

Hi I am new to Apex code development.  I am really unsure about how to write test class here. Can any one please help .

Here is the scheduler class it works fine

 

 

global class HF_Survey_OneMonth Implements Schedulable 
{
    
    global void execute(SchedulableContext sc)
    {
        sendSurvey();
    }
    
    
    
    public void SendSurvey()
    {
         // Get the most recently created config object.
         Config_Object__c config = [Select HFSurveyCode__c, Survey_Date__C, SOQL_Query__C from Config_Object__C 
                                    where Name ='HostFamily_Survey'];
         List<Opportunity> oppList = Database.query(config.SOQL_Query__c);
         
         
             List<Account> accList = new List<Account>();             
                   for(Opportunity opp:oppList)
                     {
                        if(opp.AccountId!= null)
                        {
                          Account acc = opp.Account;
                          if(acc.Survey_Code__c != String.valueOf(config.HFSurveyCode__c) || acc.Survey_Opp_Id__c != opp.Id)
                           {
                             string oppcode= opp.Id;
                             acc.Survey_Code__c = String.valueOf(config.HFSurveyCode__c); 
                             acc.Survey_Dt__c = config.Survey_Date__c;
                             acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                           }  
                         accList.add(acc); 
                        }
                     }
                update accList;  
                          
     }
  }

 

 

But to the test class i have written the code coverage says it covered 0 lines .And how do i deply it to production. Please help. Here is the test class i have written

 

 

@isTest

private class test_Config_Survey {

 

    static testMethod void myUnitTest() {

        // TO DO: implement unit test

        //Test.startTest();

        Config_Object__c config = [Select HFSurveyCode__c, Survey_Date__C, SOQL_Query__C from Config_Object__C 

                                    where Name ='HostFamily_Survey' limit 1];

 

        for(Opportunity oppList: [Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name 

                                      From Opportunity o  

                                      where o.StageName='Active' 

                                      AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 

                                      AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60 limit 1])              

 

 

      Account acclist = new Account();     

      acclist = oppList.Account;

      if(acclist.Survey_Code__c !=config.HFSurveyCode__c || acclist.Survey_Opp_Id__c != '0064000000CsXem')

      {

      acclist.Survey_Code__c=config.HFSurveyCode__c ;

      acclist.Survey_Opp_Id__c = '0064000000CsXem';

      acclist.Survey_Dt__c=Date.today();

      }

      

      update acclist;  

      //Test.stopTest();    

    }

}

 

 I have a custome object built  names Config_Object__c from which i need to access the values to my scheduler class.

 

Here is the code. please suggest if you have any ideas.

 

My Config_Object__C has fields 

1.HFSurveyCode__c="HF1Mrov'

 

2.Survey_Date__c

 

3.SOQL_query="Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c,                                                        o.Account.Survey_Code__c, o.Account.Name 

                                      From Opportunity o 

                                      where o.StageName='Active' 

                                      AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 

                                      AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60"

 

 

global class HF_Survey_OneMonth Implements Schedulable 
{
    
    global void execute(SchedulableContext sc)
    {
        sendSurvey();
    }
    
    
    
    public void SendSurvey()
    {
     //string query = Config_Object__c.SOQL_Query__c;
    ERROR here: Entities should be explictly specified in SOSL call in APEX.
 I want to reference my SOQL_query from custom object
         List<Opportunity> oppList =[ Config_Object__c.SOQL_Query__c];                               
                    
             List<Account> accList = new List<Account>();
             
                   for(Opportunity opp:oppList)
                     {
                        if(opp.AccountId!= null)
                        {
                          Account acc = opp.Account;
                          if(acc.Survey_Code__c != String.valueOf(Config_Object__c.HFSurveyCode__c))
                           {
                             string oppcode= opp.Id;
                             acc.Survey_Code__c = String.valueOf(Config_Object__c.HFSurveyCode__c);
                             acc.Survey_Dt__c = Config_Object__c.Survey_Date__c;
                             acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                           }                  
                        
                       else if(acc.Survey_Opp_Id__c != opp.Id)
                          {
                             string oppcode= opp.Id;
                             acc.Survey_Code__c = String.valueOf(Config_Object__c.HFSurveyCode__c);
                             acc.Survey_Dt__c = Config_Object__c.Survey_Date__c;
                             acc.Survey_Opp_Id__c = oppcode.subString(0,15);
                          }
                         accList.add(acc); 
                        }
                     }
                update accList;          
              
     }
  }

 

 

 

Please suggest what should be done.

Hi,

 

I need to develop a Scheduler class to generate a report. And my class should update the custom fields in Account Object relating to Opportunity (with look up field as Account in it). 

 

Here is the code.

 

 

global class HF_Survey_OneMonth Implements Schedulable 
{
    
    global void execute(SchedulableContext sc)
    {
        sendSurvey();
    }
      
    
    public void SendSurvey()
    {
         List<Opportunity> oppList = [Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name 
                                      From Opportunity o 
                                      where o.StageName='Active' 
                                      AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 
                                      AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60];                               
                    
             List<Account> accList = new List<Account>();
             
                   for(Opportunity opp:oppList)
                     {
                        if(opp.AccountId!= null)
                        {
                          Account acc = opp.Account;
                          if(acc.Survey_Code__c != 'HF1MoArv')
                           {
                             acc.Survey_Code__c = 'HF1MoArv';
                             acc.Survey_Dt__c = Date.today().addDays(1);
                             //acc.Survey_Opp_Id__c = acc.Id;
                           }                  
                        
                         else if(acc.Survey_Opp_Id__c != acc.Id)
                          {
                             acc.Survey_Code__c = 'HF1MoArv';
                             acc.Survey_Dt__c = Date.today().addDays(1);
                             //acc.Survey_Opp_Id__c = acc.Id;
                          }
                         accList.add(acc); 
                        }
                     }
                update accList;          
              
     }
  }
In here i am unable to check condition /Update Survey_Opp_Id__c field which is in Account . AccountName(Field Name:Account) is a Lookup field in Opportunity .  Here the Survey_Opp_Id__c should check for condition if it is equal to Opportunity ID if it  is not it should update the  Survey_Opp_Id__c with the Opportunity ID.
Please Help!
Thank you,
Brad.

 

 

Hi,

 

I need to Update my custom fields in Account Object on Reports.

 

I have the query retrieving my data. After i check the condition i need to update my fields.

for one of the custom field it should be updated with the Opportunity ID. 

How should i retrieve it from the query and update the field.

 

And also it should Update as a 15 character ID. 

 

 

 

global class HF_Survey_OneMonth Implements Schedulable 
{
    
    global void execute(SchedulableContext sc)
    {
        sendSurvey();
    }
    
    
    
    public void SendSurvey()
    {
        List<Account> accToUpdate = [Select Survey_Opp_Id__c, Survey_Dt__c, Survey_Code__c, Name, Id
                                           From Account 
                                           where Id IN (Select AccountId from Opportunity o
                                               Where o.StageName='Active'
                                               AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30
                                               AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60)];                               
                    
          for(Account a : accToUpdate)
          {
             if(a.Survey_Code__c != 'HF1MoArv')
              {
                a.Survey_Code__c = 'HF1MoArv';
                a.Survey_Dt__c = Date.today().addDays(1);
              }
          }
                
    }
}   

 

 

Please Help.

Thank you.

I have a custom objects that receives records from an external system.  When the records come in I want to assign them to a specific user to maintain security.  I believe a trigger would work best but have no experience creating one.  Can anyone help?
  • March 02, 2010
  • Like
  • 0