• narendra jagwan
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 4
    Replies
 i m trying to integration salesforce with heroku . i create heroku postgres dataclip "https://dataclips.heroku.com/syneoppllnrictclhumigotdrbsl#employees-1" .then create http class in salesforce .but i got  Status=Moved Permanently, StatusCode=301. how  we can solve this issue .???
 
  code



  public class herokuDaaclip {

    @future(callout=true)
  public static void get() {
         
        HttpRequest req = new HttpRequest();
        
        //req.setHeader('content-type','application/json;charset=utf-8');
        // https://dataclips.heroku.com/fcroecrluhwltbjinstfqmwyneex.json
        req.setEndpoint('https://postgres.heroku.com/dataclips/syneoppllnrictclhumigotdrbsl.json');
        req.setMethod('GET');

        Http http = new Http();
        HTTPResponse res = http.send(req);
        system.debug('@@@@@@@@@@@@@' + res.getbody());
        if(res.getStatusCode()!=200)
           {
            System.debug('Error from '+ req.getEndpoint() +':'+res.getStatusCode()+''+res.getStatus());
              }
        
           
        string resbody = (res.getbody()).replace('','');
        system.debug('fffffffffffff'+resbody);
       // System.debug('Data Clip response code: '+res.getStatusCode()+'. Status: '+res.getStatus());
       // return (List<JSON2Apex>)System.JSON.deserialize(resbody, List<JSON2Apex>.class);
        
    }
}
 
public with sharing class installNewsObjectController {

//get sobject Name
public String sObjectName{get;set;}

// get sobject Label
public String sObjectLabel{get;set;}

//for delete sobject from this Object
public String deleteSelected{get;set;}

private String SOBJECT_FIELD_NAME;
private String SOBJECT_FIELD_LABEL;

private String SELECTED_DELETE;

public MetadataService.AsyncResult result {get;set;}
    public SelectOption[] selectedsobject { get; set; }
    public SelectOption[] allsobject {get; set;}   
   
    public SelectOption[] deletionSobject { get; set; }
    public SelectOption[] existingsobject {get; set;}   
    public String message {get; set;}

// create Field for custom object
public PageReference createField(){
       
        // Create a Custom Field
        MetadataService.CustomField customField = new MetadataService.CustomField();     
        customField.fullName = 'SA_S3_File__c.'+SOBJECT_FIELD_LABEL.replaceAll(' ','')+'__c';       
        customField.label = SOBJECT_FIELD_LABEL;
        system.debug('zzzzzzz'+ customField.label);
        customField.referenceTo = SOBJECT_FIELD_NAME;
        customField.relationshipLabel = (SOBJECT_FIELD_LABEL+'_SA_Files').replaceAll(' ','');
        customField.relationshipName = SOBJECT_FIELD_LABEL.replaceAll(' ','');
        customField.type_x = 'Lookup';         
        result = createService().create(new List<MetadataService.Metadata> { customField })[0];    
         system.debug('@@@@@@@'+result);
        // Display status of the request
        displayStatus();  
        return null;
    }


    //constructor
    public installNewsObjectController() {
       
        //get inintialize
        init();
       
        //check Already existing Object
        alreadySelectedObject();
         
    }
   
    public void init(){    
        
        selectedsobject = new List<SelectOption>();       
         List<Schema.SObjectType> listOfSobject = Schema.getGlobalDescribe().Values();  
         List<SelectOption> options = new List<SelectOption>();
         allsobject = new List<SelectOption>();
         options.add(new SelectOption('','---None---'));
          for(Schema.SObjectType sObj : listOfSobject){
                       
             if( !sObj.getDescribe().isCustomSetting()
                 && (sObj.getDescribe().getName()== 'Account'
                 || sObj.getDescribe().getName() == 'Contact'
                 || sObj.getDescribe().getName()== 'Opportunity'
                 || sObj.getDescribe().isCustom())){               
                allsobject.add(new SelectOption(sObj.getDescribe().getName()+'#'+sObj.getDescribe().getLabel(),sObj.getDescribe().getLabel()));   
               system.debug('<<<<<<<'+allsobject);
             }       
          }
         allsobject.sort();
    }

public PageReference deleteField(){
       
        // Delete a Custom Field
        MetadataService.CustomField customField = new MetadataService.CustomField();
        customField.fullName = 'SA_S3_File__c.'+SELECTED_DELETE.replaceAll(' ','_');
       
                           
        system.debug('&&&&&&&'+customField.fullName );
        result = createService().deleteMetadata(new List<MetadataService.Metadata> { customField })[0]; 
        system.debug('######'+result);   
        list<SA_Upload_Setting__c> setting = [Select id from SA_Upload_Setting__c where Object_Name__c =:'Opportunity'];
        delete setting;
        system.debug('aaaaaaaa'+setting); 
        // Display status of the request
        checkStatus();
        return null;  
    }
   
   
    public PageReference checkStatus(){    
        // Check status of the request
        result = createService().checkStatus(new List<String> { result.Id })[0];
        system.debug('************'+result);
        displayStatus();       
        return null;   
    }
   
    private void displayStatus(){
    
        // Inspect the AsyncResult and display the result
        ApexPages.addMessage(
            new ApexPages.Message(ApexPages.Severity.Info,
                result.done ? 'Request completed' : 'Request in progress...'));
        if(result.state == 'Error')
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, result.message));
        if(result.done)
            result = null;
    }
       
    private static MetadataService.MetadataPort createService(){
     
        // Create the Metadata API service stub and authenticate
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        return service;    
    }


   
   
   
    public void alreadySelectedObject(){
    
      SObjectType ObjectType =  Schema.getGlobalDescribe().get('SA_S3_File__c');
      Schema.DescribeSObjectResult R = ObjectType.getDescribe();
   Map<String,Schema.SObjectField> fieldsMap = R.fields.getMap();
  
   deletionSobject = new List<SelectOption>();       
         List<Schema.SObjectType> listOfSobject = Schema.getGlobalDescribe().Values();  
         List<SelectOption> options = new List<SelectOption>();
         existingsobject = new List<SelectOption>();
           
    for(String ObjField : fieldsMap.keySet()){
                
         if((fieldsMap.get(ObjField).getDescribe().isCustom() && String.valueOf(fieldsMap.get(ObjField).getDescribe().getType()) == 'REFERENCE'))
            existingsobject.add(new SelectOption(fieldsMap.get(ObjField).getDescribe().getName(),fieldsMap.get(ObjField).getDescribe().getLabel()));
                   
        }   
    }

    public PageReference createFields() {
       
        message = 'Selected object: ';
        Boolean first = true;
        for ( SelectOption so : selectedsobject ) {
           
            if (!first) {
                message += ', ';
            }
            SOBJECT_FIELD_NAME = so.getValue().split('#')[0].trim();
            SOBJECT_FIELD_LABEL = so.getLabel();
            createField();
            message += so.getLabel() + ' (' + so.getValue() + ')';
            first = false;
        }       
        return null;      
    }
   
      public PageReference deleteFields() {
       
        message = 'Deleted Fields:';
        Boolean first = true;
        for ( SelectOption so : deletionSobject ) {
           
            if (!first) {
                message += ', ';
            }
            SELECTED_DELETE = so.getValue();           
            deleteField();
            message += so.getLabel() + ' (' + so.getValue() + ')'; 
            system.debug('^^^^^^^^^^'+message);
            first = false;
        }       
        return null;      
    }
   
}
how we can check the lookup  is custom object  or standard object in dynamically ways..
how we can build the test class of this wrapper class ... my code coverage only 71% plz suggest me what code that's 100% c





public PageReference processSelected()
                                                     {
                                       
                                                                
                       
                           //We create a new list of Contacts that we be populated only with Contacts if they are selected

                  selectedEmployee = new List<Employee1_del__c>();



                          //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list

                 for(eEmployee eCon: getEmployee())
                    {

                             if(eCon.selected == true)
                              {

                                   selectedEmployee.add(eCon.con);

                                }

                       }

                             system.debug('<<<<<<<<'+selectedEmployee[0].id);

                             // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc

                             System.debug('These are the selected Contacts...');
                       
                                            for(Employee1_del__c con: selectedEmployee)
                                              {
                       
                                                     system.debug('+++++++++'+con);
                       
                                                  }
                       
                                                   // we need this line if we performed a write operation  because getContacts gets a fresh list now    
                                                   employeeList=null;
                               
                                          PageReference pg = new PageReference('https://ap1.salesforce.com/'+selectedEmployee[0].id+'/e?retURL=%2F');
                                              pg.setRedirect(true);
                                              return pg;

                         }


public  void dele()
        {
      
                 list<Employee1_del__c> c=[Select id from Employee1_del__c];
       
                 delete c;
            }
          

       // delete select
     public void se()
            { 
         List<Employee1_del__c> accToDel = new List<Employee1_del__c>(); 
         for(eEmployee wrap : employeeList)
             { 
                /*Check if record is selected*/ 
                       if(wrap.selected)
                          { 
                              accToDel.add(wrap.con); 
                             } 
                      }
<apex:page standardController="Account" recordSetVar="Accounts">
<apex:dataList var="a" value="{!Accounts}" type="1">
     {!a.name}
    </apex:dataList>
    </apex:page>
    i write thats code bt no record show in ma vf page .. what problem ma org..  pllzzzz help me
how we can delete  a single id in the contact list frome custom controller  like this pageUser-added image
 i m trying to integration salesforce with heroku . i create heroku postgres dataclip "https://dataclips.heroku.com/syneoppllnrictclhumigotdrbsl#employees-1" .then create http class in salesforce .but i got  Status=Moved Permanently, StatusCode=301. how  we can solve this issue .???
 
  code



  public class herokuDaaclip {

    @future(callout=true)
  public static void get() {
         
        HttpRequest req = new HttpRequest();
        
        //req.setHeader('content-type','application/json;charset=utf-8');
        // https://dataclips.heroku.com/fcroecrluhwltbjinstfqmwyneex.json
        req.setEndpoint('https://postgres.heroku.com/dataclips/syneoppllnrictclhumigotdrbsl.json');
        req.setMethod('GET');

        Http http = new Http();
        HTTPResponse res = http.send(req);
        system.debug('@@@@@@@@@@@@@' + res.getbody());
        if(res.getStatusCode()!=200)
           {
            System.debug('Error from '+ req.getEndpoint() +':'+res.getStatusCode()+''+res.getStatus());
              }
        
           
        string resbody = (res.getbody()).replace('','');
        system.debug('fffffffffffff'+resbody);
       // System.debug('Data Clip response code: '+res.getStatusCode()+'. Status: '+res.getStatus());
       // return (List<JSON2Apex>)System.JSON.deserialize(resbody, List<JSON2Apex>.class);
        
    }
}
 
how we can build the test class of this wrapper class ... my code coverage only 71% plz suggest me what code that's 100% c





public PageReference processSelected()
                                                     {
                                       
                                                                
                       
                           //We create a new list of Contacts that we be populated only with Contacts if they are selected

                  selectedEmployee = new List<Employee1_del__c>();



                          //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list

                 for(eEmployee eCon: getEmployee())
                    {

                             if(eCon.selected == true)
                              {

                                   selectedEmployee.add(eCon.con);

                                }

                       }

                             system.debug('<<<<<<<<'+selectedEmployee[0].id);

                             // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc

                             System.debug('These are the selected Contacts...');
                       
                                            for(Employee1_del__c con: selectedEmployee)
                                              {
                       
                                                     system.debug('+++++++++'+con);
                       
                                                  }
                       
                                                   // we need this line if we performed a write operation  because getContacts gets a fresh list now    
                                                   employeeList=null;
                               
                                          PageReference pg = new PageReference('https://ap1.salesforce.com/'+selectedEmployee[0].id+'/e?retURL=%2F');
                                              pg.setRedirect(true);
                                              return pg;

                         }


public  void dele()
        {
      
                 list<Employee1_del__c> c=[Select id from Employee1_del__c];
       
                 delete c;
            }
          

       // delete select
     public void se()
            { 
         List<Employee1_del__c> accToDel = new List<Employee1_del__c>(); 
         for(eEmployee wrap : employeeList)
             { 
                /*Check if record is selected*/ 
                       if(wrap.selected)
                          { 
                              accToDel.add(wrap.con); 
                             } 
                      }