• Rahul Gupta 166
  • NEWBIE
  • 40 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
Hi,
For any reason I can't import the csv file in the trailhead Admin Beginner / Data Management / Import Data Unit and check the challenge.
I seem to have imported the data correctly but I can't map all the fields. Here is what I did:
User-added image
error message

I'm supposed to map the required field Contact: Prequalified Amount.
Have I missed an important step?

Thanks a lot to help me checking this 500 points challenge :)
Hi Can some one help me with test class of the following code :
 
public with sharing class MetadataServiceExamples{
   
    
 public static map<String,map<String,map<string,string>>> profiledata(set<String> prfset){
 map<String,map<String,map<string,string>>> fillprofiledetail=new map<String,map<String,map<string,string>>>();
   MetadataService.MetadataPort service = createService();
   
  // String [] arrayOfProfileName = new List<String>();
    //   arrayOfProfileName.addAll(prfset);
       
   for(String strprf:prfset){
   String StrTmpProfile= strprf;
    if(strprf == 'System Administrator')
     {
        strprf= 'Admin';
     }
    if(strprf == 'Solution Manager')
     {
        strprf= 'SolutionManager';
     } 
     if(strprf == 'Contract Manager')
     {
        strprf= 'ContractManager';
     } 
     if(strprf == 'Standrad Marketing User')
     {
        strprf= 'StandradAul';
     } 
     if(strprf == 'Standard User')
     {
        strprf= 'Standard';
     }
     if(strprf == 'Marketing User')
     {
        strprf= 'MarketingProfile';
     } 
     if(strprf=='Standard Platform User')
      {
        strprf= 'StandradAul';
      }
     if(strprf=='High Volume Customer Portal')
     {
       strprf= 'HighVolumePortal';
     }
     
     
      String [] arrayOfProfileName = new List<String>();
      arrayOfProfileName.add(strprf); 
   map<String,map<string,string>>  innermap=new map<String,map<string,string>>();
   //MetadataService.Profile admin = (MetadataService.Profile) service.readMetadata('Profile', new String[] {strprf}).getRecords()[0];
   MetadataService.Profile admin = (MetadataService.Profile) service.readMetadata('Profile', arrayOfProfileName).getRecords()[0];
   system.debug(admin.fullName); 
   
   //User Permissions
   
   map<string,string> innerininnermap=new map<string,string>();
   if(admin.userPermissions.size()>0){
   for(MetadataService.ProfileUserPermission ptv : admin.userPermissions){
   
      innerininnermap.put(''+ptv.name,''+ptv.enabled);
     //system.debug('User Permission = ' + ptv.name + ' & ' + 'visibility = ' + ptv.enabled);
     }
     innermap.put('userPermissions', innerininnermap); 
    }
   
  //Tab visiblity
  if(admin.tabVisibilities.size()>0){
   innerininnermap=new map<string,string>();
   for(MetadataService.ProfileTabVisibility ptv : admin.tabVisibilities){
      innerininnermap.put(''+ptv.tab,''+ptv.visibility);
     //system.debug('tab name = ' + ptv.tab + ' & ' + 'visibility = ' + ptv.visibility);
     }
    innermap.put('tabVisibilities', innerininnermap); 
    }
    
  //Application Visiblity
  if(admin.applicationVisibilities.size()>0){
   innerininnermap=new map<string,string>();      
    for(MetadataService.ProfileApplicationVisibility pav : admin.applicationVisibilities){
     innerininnermap.put(''+pav.application,''+pav.visible);
     //  system.debug('app name = ' + pav.application+ ' & ' + 'visibility = ' + pav.visible);
    }   
  innermap.put('applicationVisibilities', innerininnermap);  
  }
  
   //Apex Class
  if(admin.classAccesses.size()>0){  
  innerininnermap=new map<string,string>();  
  for(MetadataService.ProfileApexClassAccess pac : admin.classAccesses){
       innerininnermap.put(''+pac.apexClass,''+pac.enabled);
//     system.debug('Apex class = ' + pac.apexClass+ ' & ' + 'visibility = ' + pac.enabled);
    }   
  innermap.put('classAccesses', innerininnermap); 
  }
 
  //Apex Page
  if(admin.pageAccesses.size()>0){  
  innerininnermap=new map<string,string>();  
  for(MetadataService.ProfileApexPageAccess pa : admin.pageAccesses){
    innerininnermap.put(''+pa.apexPage,''+pa.enabled);
    //system.debug('Apex Page= ' + pa.apexPage+ ' & ' + 'visibility = ' + pa.enabled);
  }   
  innermap.put('pageAccesses', innerininnermap);
 }   
   
   
   
     //recordtype     
  innerininnermap=new map<string,string>();  
  if(admin.recordTypeVisibilities.size()>0){ 
  for(MetadataService.ProfileRecordTypeVisibility pa : admin.recordTypeVisibilities)
    {
            innerininnermap.put(''+pa.recordType,''+pa.visible);

    }   
  innermap.put('recordTypeVisibilities', innerininnermap);   
    } 
     
   
    
    
    innerininnermap=new map<string,string>();  
  if(admin.recordTypeVisibilities.size()>0){ 
  for(MetadataService.ProfileRecordTypeVisibility pa : admin.recordTypeVisibilities)
    {
            innerininnermap.put(''+pa.recordType,''+pa.visible);

    }   
  innermap.put('recordTypeVisibilities', innerininnermap);   
    } 
     
     
   fillprofiledetail.put(StrTmpProfile,innermap);  
  }
   return   fillprofiledetail;
   }
 
   public static map<String,map<String,map<string,List<string>>>> profiledataObject (set<String> prfset)
    {
    map<String,map<String,map<string,List<string>>>> fillprofiledetail1=new map<String,map<String,map<string,List<string>>>>();
    MetadataService.MetadataPort service = createService();
    for(String strprf:prfset){
     String StrTmpProfile= strprf;
    if(strprf == 'System Administrator')
     {
        strprf= 'Admin';
     }
    if(strprf == 'Solution Manager')
     {
        strprf= 'SolutionManager';
     } 
     if(strprf == 'Contract Manager')
     {
        strprf= 'ContractManager';
     } 
     if(strprf == 'Standrad Marketing User')
     {
        strprf= 'StandradAul';
     } 
     if(strprf == 'Standard User')
     {
        strprf= 'Standard';
     }
     if(strprf == 'Marketing User')
     {
        strprf= 'MarketingProfile';
     } 
     if(strprf=='Standard Platform User')
      {
        strprf= 'StandradAul';
      }
     if(strprf=='High Volume Customer Portal')
     {
       strprf= 'HighVolumePortal';
     }
     
     
      String [] arrayOfProfileName = new List<String>();
      arrayOfProfileName.add(strprf);
      map<String,map<string,List<string>>>  innermap=new map<String,map<string,List<string>>>();      
      MetadataService.Profile admin = (MetadataService.Profile) service.readMetadata('Profile', arrayOfProfileName).getRecords()[0];
      system.debug(admin.fullName); 
      map<string,List<string>>innerininnermap=new map<string,List<string>>();  
       if(admin.objectPermissions.size()>0){ 
        for(MetadataService.ProfileObjectPermissions pa : admin.objectPermissions)
          {
           
           List<String>Temp = new List<String>();
           Temp.add(''+pa.allowCreate);
           Temp.add(''+pa.allowDelete);
           Temp.add(''+pa.allowEdit);
           Temp.add(''+pa.allowRead);
           Temp.add(''+pa.modifyAllRecords);
           Temp.add(''+pa.viewAllRecords);
           innerininnermap.put(''+pa.object_x,Temp);
            

        }   
      innermap.put('objectPermissions', innerininnermap);   
    } 
    fillprofiledetail1.put(StrTmpProfile,innermap);
    }
    return fillprofiledetail1;
    }
    
    
    public static map<String,map<String,map<string,List<string>>>> profiledataField (set<String> prfset)
    {
    map<String,map<String,map<string,List<string>>>> fillprofiledetail2 =new map<String,map<String,map<string,List<string>>>>();
    MetadataService.MetadataPort service = createService();
    for(String strprf:prfset){
     String StrTmpProfile= strprf;
   if(strprf == 'System Administrator')
     {
        strprf= 'Admin';
     }
    if(strprf == 'Solution Manager')
     {
        strprf= 'SolutionManager';
     } 
     if(strprf == 'Contract Manager')
     {
        strprf= 'ContractManager';
     } 
     if(strprf == 'Standrad Marketing User')
     {
        strprf= 'StandradAul';
     } 
     if(strprf == 'Standard User')
     {
        strprf= 'Standard';
     }
     if(strprf == 'Marketing User')
     {
        strprf= 'MarketingProfile';
     } 
     if(strprf=='Standard Platform User')
      {
        strprf= 'StandradAul';
      }
     if(strprf=='High Volume Customer Portal')
     {
       strprf= 'HighVolumePortal';
     }
     
     
      String [] arrayOfProfileName = new List<String>();
      arrayOfProfileName.add(strprf);
      map<String,map<string,List<string>>>  innermap=new map<String,map<string,List<string>>>();      
      MetadataService.Profile admin = (MetadataService.Profile) service.readMetadata('Profile', arrayOfProfileName).getRecords()[0];
      system.debug(admin.fullName); 
      map<string,List<string>>innerininnermap=new map<string,List<string>>();  
       if(admin.fieldPermissions.size()>0){ 
        for(MetadataService.ProfileFieldLevelSecurity pa : admin.fieldPermissions)
          {
           
           List<String>Temp = new List<String>();
           Temp.add(''+pa.editable);
           Temp.add(''+pa.readable);
           
           innerininnermap.put(''+pa.field,Temp);
            

        }   
      innermap.put('fieldPermissions', innerininnermap);   
    } 
    fillprofiledetail2.put(StrTmpProfile,innermap);
    }
    return fillprofiledetail2;
    }
   
   
   
    
    
    public class MetadataServiceExamplesException extends Exception { }

    public static MetadataService.MetadataPort createService()
    {
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        return service;
    }

    /**
     * Example helper method to interpret a SaveResult, throws an exception if errors are found
     **/
    public static void handleSaveResults(MetadataService.SaveResult saveResult)
    {
        // Nothing to see?
        if(saveResult==null || saveResult.success)
            return;
        // Construct error message and throw an exception
        if(saveResult.errors!=null)
        {
            List<String> messages = new List<String>();
            messages.add(
                (saveResult.errors.size()==1 ? 'Error ' : 'Errors ') +
                    'occured processing component ' + saveResult.fullName + '.');
            for(MetadataService.Error error : saveResult.errors)
                messages.add(
                    error.message + ' (' + error.statusCode + ').' +
                    ( error.fields!=null && error.fields.size()>0 ?
                        ' Fields ' + String.join(error.fields, ',') + '.' : '' ) );
            if(messages.size()>0)
                throw new MetadataServiceExamplesException(String.join(messages, ' '));
        }
        if(!saveResult.success)
            throw new MetadataServiceExamplesException('Request failed with no specified error.');
    }

    /**
     * Example helper method to interpret a SaveResult, throws an exception if errors are found
     **/
    public static void handleDeleteResults(MetadataService.DeleteResult deleteResult)
    {
        // Nothing to see?
        if(deleteResult==null || deleteResult.success)
            return;
        // Construct error message and throw an exception
        if(deleteResult.errors!=null)
        {
            List<String> messages = new List<String>();
            messages.add(
                (deleteResult.errors.size()==1 ? 'Error ' : 'Errors ') +
                    'occured processing component ' + deleteResult.fullName + '.');
            for(MetadataService.Error error : deleteResult.errors)
                messages.add(
                    error.message + ' (' + error.statusCode + ').' +
                    ( error.fields!=null && error.fields.size()>0 ?
                        ' Fields ' + String.join(error.fields, ',') + '.' : '' ) );
            if(messages.size()>0)
                throw new MetadataServiceExamplesException(String.join(messages, ' '));
        }
        if(!deleteResult.success)
            throw new MetadataServiceExamplesException('Request failed with no specified error.');
    }
    
     public static void handleUpsertResults(MetadataService.UpsertResult upsertResult)
    {
        // Nothing to see?
        if(upsertResult==null || upsertResult.success)
            return;
        // Construct error message and throw an exception
        if(upsertResult.errors!=null)
        {
            List<String> messages = new List<String>();
            messages.add(
                (upsertResult.errors.size()==1 ? 'Error ' : 'Errors ') +
                    'occured processing component ' + upsertResult.fullName + '.');
            for(MetadataService.Error error : upsertResult.errors)
                messages.add(
                    error.message + ' (' + error.statusCode + ').' +
                    ( error.fields!=null && error.fields.size()>0 ?
                        ' Fields ' + String.join(error.fields, ',') + '.' : '' ) );
            if(messages.size()>0)
                throw new MetadataServiceExamplesException(String.join(messages, ' '));
        }
        if(!upsertResult.success)
            throw new MetadataServiceExamplesException('Request failed with no specified error.');
    }
}

 
Can someone help me how to find object access basis of the profile? My requirement is i have a drop down on basis of that i am Selecting more than One profile and on clicking fetchData button i need a table that shows profile name as table name and access of all Object for that profile. For Multiple profiles multiple tables with created
How to Dynamically Create Multiple Tabs in Excel based on MultiselectPicklist( Using Workbook and Worksheets tags)
Please help Urgently required
Hi, i have a two picklist value one has a list of object and other is a list of the fields related to object pick list(more than one field can be selected)
If a object is selected and related field are selected it should create a table with records for a particular object.
This is now working for one field in the Particular object. 
when I select the multiple fields for an object it shows error 
Exception: Invalid field name for SObject Account 

Below is vf page  for same :
<apex:page controller="objectController1"  showHeader="false" sidebar="false" > 
    <head>
        <apex:stylesheet value="{!URLFOR($Resource.LIGHTNING_RESOURCE_NAME, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
    </head>
    <apex:form > 
        <apex:pageBlock > 
            <apex:pageBlockSection > 
                <apex:pageBlockSectionItem > 
                    <apex:outputlabel value="Object Names :"/> 
                    <apex:actionRegion > 
                        <apex:selectList value="{!selectedObject}" size="1"> 
                            <apex:selectOptions value="{!ObjectNames}"/> 
                            <apex:actionSupport event="onchange" rerender="myFields"/> 
                        </apex:selectList> 
                    </apex:actionRegion> 
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem > 
                    <apex:outputlabel value="Field Names :"/> 
                    <apex:outputPanel id="myFields"> 
                        <apex:actionRegion > 
                            <apex:selectList value="{!selectedField}"  size="10" multiselect="true"> 
                                <apex:selectOptions value="{!ObjectFields}"/> 
                            </apex:selectList> 
                        </apex:actionRegion> 
                    </apex:outputPanel> 
                </apex:pageBlockSectionItem> 
                <Center>
                    <apex:commandButton value="Fetch Fields" action="{!Fetch}"/>
                </Center>
            </apex:pageBlockSection> 
        </apex:pageBlock> 
           <apex:outputPanel layout="block">
                <apex:pageBlock >
                    <apex:pageBlockSection >
                        <apex:pageblockTable value="{!lstobj}"  var="querydata">
                            <apex:repeat value="{!fnlFields}" var="coldata">
                            <apex:column value="{!querydata[coldata]}">
                             </apex:column>
                                </apex:repeat>
                        </apex:pageblockTable>
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </apex:outputPanel>   
    </apex:form> 
</apex:page>
Below is Controller for the Same :
 
public class objectController1{
    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    public String selectedObject {get; set;}
    public String selectedField {get; set;}
    public String picklistValue {get; set;}
    public List<sObject> lstobj {get; set;}
    public List<String> lstfields {get; set;}
    public List<String> fnlFields {get;set;}
    public List<SelectOption> fieldNames {get; set;}
    public List<wrapData> bindData {get;set;}
    
    Public objectController1(){   
        selectedObject ='account';
        //system.debug('HI This is fields'+selectedField );
    }
    
    public List<SelectOption> getObjectNames(){
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        
        for(String name : entities){
            objNames.add(new SelectOption(name,name));
        }
        return objNames;
    }
    
    public List<SelectOption> getObjectFields(){
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
        Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
        fieldNames = new List<SelectOption>();
        for (String fieldName: fieldMap.keySet()){  
            fieldNames.add(new SelectOption(fieldName,fieldName));
            //fieldMap.get(fieldName).getDescribe().getLabel();//It provides to get the object fields label.
        }
        System.debug('fieldNames-----'+fieldNames);
        return fieldNames;
    }
    
    
    public PageReference Fetch(){
        
        lstobj = new List<sObject>();
        lstfields= new List<String>();
        bindData = new List<wrapData>(); 
        fnlFields = new List<String>(); 
        //System.debug('Select'+selectedField +'From'+selectedObject);
        String s1= selectedField.removeStart('[');
        String s2= s1.removeEnd(']');
        
        String Query='Select '+s2+' From '+selectedObject;
        
        
        lstobj= Database.query(Query);
        System.debug('List '+lstobj);
        
        lstfields = s2.split(',');
        //System.debug('List of fields '+lstfields);
        for(String s : lstfields){
        
        fnlFields.add(s);
        
        }
        System.debug(fnlFields);
        
        
        //bindData.add(new wrapData(selectedField,lstobj));
        return null; 
    }    
}

Please help me to create a table with more than one field with record 
Thanks in Advance
Rahul



 
I have a Field on account called Isactive__c   which is checkbox type and i want when ever checkbox is true
Account number field (standrad field) becomes read only . If there is existing value then it can be only viewed but if there is no value you cant edit it (only by customization, no use of trigger or apex)
How to Dynamically Create Multiple Tabs in Excel based on MultiselectPicklist( Using Workbook and Worksheets tags)
Please help Urgently required
Hi, i have a two picklist value one has a list of object and other is a list of the fields related to object pick list(more than one field can be selected)
If a object is selected and related field are selected it should create a table with records for a particular object.
This is now working for one field in the Particular object. 
when I select the multiple fields for an object it shows error 
Exception: Invalid field name for SObject Account 

Below is vf page  for same :
<apex:page controller="objectController1"  showHeader="false" sidebar="false" > 
    <head>
        <apex:stylesheet value="{!URLFOR($Resource.LIGHTNING_RESOURCE_NAME, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
    </head>
    <apex:form > 
        <apex:pageBlock > 
            <apex:pageBlockSection > 
                <apex:pageBlockSectionItem > 
                    <apex:outputlabel value="Object Names :"/> 
                    <apex:actionRegion > 
                        <apex:selectList value="{!selectedObject}" size="1"> 
                            <apex:selectOptions value="{!ObjectNames}"/> 
                            <apex:actionSupport event="onchange" rerender="myFields"/> 
                        </apex:selectList> 
                    </apex:actionRegion> 
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem > 
                    <apex:outputlabel value="Field Names :"/> 
                    <apex:outputPanel id="myFields"> 
                        <apex:actionRegion > 
                            <apex:selectList value="{!selectedField}"  size="10" multiselect="true"> 
                                <apex:selectOptions value="{!ObjectFields}"/> 
                            </apex:selectList> 
                        </apex:actionRegion> 
                    </apex:outputPanel> 
                </apex:pageBlockSectionItem> 
                <Center>
                    <apex:commandButton value="Fetch Fields" action="{!Fetch}"/>
                </Center>
            </apex:pageBlockSection> 
        </apex:pageBlock> 
           <apex:outputPanel layout="block">
                <apex:pageBlock >
                    <apex:pageBlockSection >
                        <apex:pageblockTable value="{!lstobj}"  var="querydata">
                            <apex:repeat value="{!fnlFields}" var="coldata">
                            <apex:column value="{!querydata[coldata]}">
                             </apex:column>
                                </apex:repeat>
                        </apex:pageblockTable>
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </apex:outputPanel>   
    </apex:form> 
</apex:page>
Below is Controller for the Same :
 
public class objectController1{
    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    public String selectedObject {get; set;}
    public String selectedField {get; set;}
    public String picklistValue {get; set;}
    public List<sObject> lstobj {get; set;}
    public List<String> lstfields {get; set;}
    public List<String> fnlFields {get;set;}
    public List<SelectOption> fieldNames {get; set;}
    public List<wrapData> bindData {get;set;}
    
    Public objectController1(){   
        selectedObject ='account';
        //system.debug('HI This is fields'+selectedField );
    }
    
    public List<SelectOption> getObjectNames(){
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        
        for(String name : entities){
            objNames.add(new SelectOption(name,name));
        }
        return objNames;
    }
    
    public List<SelectOption> getObjectFields(){
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
        Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
        fieldNames = new List<SelectOption>();
        for (String fieldName: fieldMap.keySet()){  
            fieldNames.add(new SelectOption(fieldName,fieldName));
            //fieldMap.get(fieldName).getDescribe().getLabel();//It provides to get the object fields label.
        }
        System.debug('fieldNames-----'+fieldNames);
        return fieldNames;
    }
    
    
    public PageReference Fetch(){
        
        lstobj = new List<sObject>();
        lstfields= new List<String>();
        bindData = new List<wrapData>(); 
        fnlFields = new List<String>(); 
        //System.debug('Select'+selectedField +'From'+selectedObject);
        String s1= selectedField.removeStart('[');
        String s2= s1.removeEnd(']');
        
        String Query='Select '+s2+' From '+selectedObject;
        
        
        lstobj= Database.query(Query);
        System.debug('List '+lstobj);
        
        lstfields = s2.split(',');
        //System.debug('List of fields '+lstfields);
        for(String s : lstfields){
        
        fnlFields.add(s);
        
        }
        System.debug(fnlFields);
        
        
        //bindData.add(new wrapData(selectedField,lstobj));
        return null; 
    }    
}

Please help me to create a table with more than one field with record 
Thanks in Advance
Rahul



 
Hi,
For any reason I can't import the csv file in the trailhead Admin Beginner / Data Management / Import Data Unit and check the challenge.
I seem to have imported the data correctly but I can't map all the fields. Here is what I did:
User-added image
error message

I'm supposed to map the required field Contact: Prequalified Amount.
Have I missed an important step?

Thanks a lot to help me checking this 500 points challenge :)
I have a Field on account called Isactive__c   which is checkbox type and i want when ever checkbox is true
Account number field (standrad field) becomes read only . If there is existing value then it can be only viewed but if there is no value you cant edit it (only by customization, no use of trigger or apex)
We have an exisitng VF page where FIELDSETS is been used. FIELDSET has multiple fields like Text,Textarea,checkbox,richtext etc.
We have to apply lightning stye using Lightning desgin system but since the fields are commign dynamically .
We are unable to render styles on individual fields . Is there any solution on this ?


            <apex:pageBlockSection title="Information" columns="1" showHeader="true" 
                collapsible="false" rendered="{!layoutType == 1}">
               
                <apex:repeat value="{!$ObjectType.INFO__c.FieldSets.Marketing_Information}" var="field">
                    <apex:inputField value="{!objInteraction[field]}"/>
                </apex:repeat>
            </apex:pageBlockSection>