• RamkumarVTR
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies
I have a requirement where i need to get the object name and field api name as a input and get the agreegate results where the values doesnt exist in system with counts. i have written the code as below mentioned, can you please evaluate and confirm is it right.
 
<apex:page standardController="InvalidPicklistObjectType__c" extensions="InvalidPicklistReportController">  
    <style type="text/css">
        body {background: #F3F3EC; padding-top: 15px}
    </style>
    <apex:form >
        <apex:pageBlock title="Search for Invalid Picklist Value" id="block" mode="edit">
            <apex:pageMessages />
				<apex:pageBlockSection >
					<apex:pageBlockSectionItem >
						<apex:selectList value="{!Object API Name}" size="1" id="Object_API_Name__c">
							<apex:actionSupport event="onchange" reRender="newvalue" />
							<apex:selectOptions value="{!InvalidPicklistObjectType__c.Object_API_Name__c}"/>
						</apex:selectList>
						<apex:selectList value="{!Field API Name}" size="1" id="Field_API_Name__c">
							<apex:actionSupport event="onchange" reRender="newvalue" />
							<apex:selectOptions value="{!InvalidPicklistObjectType__c.Field_API_Name__c}"/>
						</apex:selectList>
                    <apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:actionStatus id="status" startText="Generating Report... please wait..."/>
            <apex:pageBlockSection id="resultsBlock" columns="1">
                <apex:pageBlockTable value="{!searchResults}" var="o" rendered="{!NOT(ISNULL(searchResults))}">                                      
                    </apex:column>
                    <apex:column value="{!o.Object_API_Name__c}"/>
                    <apex:column value="{!o.Field_API_Name__c}"/>
                    <apex:column value="{!o.InvalidPicklistValues__c}"/>
					<apex:column value="{!o.Count__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>

        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class InvalidPicklistReportController {

//added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
    // the actual account
    private Account a;
    // the results from the search. do not init the results or a blank rows show up initially on page load
    public List<ObjectFieldType__c> searchResults {get;set;}

    // the text in the search box
    public string searchText {
        get {
            if (searchText == null) searchText = 'Acme'; // prefill the serach box for ease of use
            return searchText;
        }
        set;
    }

    public InvalidPicklistReportController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        this.a = (InvalidPicklistObjectType__c)controller.getRecord();

    }

    // fired when the search button is clicked
    public PageReference search() {
        if (searchResults == null) {
            searchResults = new List<ObjectFieldType__c>(); // init the list if it is null
        } else {
            searchResults.clear(); // clear out the current results if they exist
        }
        // Note: you could have achieved the same results as above by just using:
        // searchResults = new List<categoryWrapper>();

        // use some dynamic soql to find the related opportunities by name
		
		String ObjectAPIName = InvalidPicklistObjectType__c.Object_API_Name__c; 
		String FieldAPIName= InvalidPicklistObjectType__c.Field_API_Name__c
		
		List <String> getPicklistValues(ObjectAPIName,FieldAPIName);
		
		AggregateResult[] groupedResults=[SELECT Specialty_1_vod__c, count(Id) FROM Account GROUP BY Specialty_1_vod__c];
		 
		for (AggregateResult ar : groupedResults){

			for (String availablepickval: getPicklistValues){
			
			 if(ar.get('Specialty_1_vod__c') != availablepickval){
			 
				List <ObjectFieldType__c> objectType = new List <ObjectFieldType__c>();
				
                System.debug('Picklist values' + ar1.get('Specialty_1_vod__c'));
                System.debug('Picklist count' + ar.get('expr0'));
                integer myDecimal1 = integer.valueOf(ar.get('expr0'));
                objectType.Count__c=myDecimal1 ;
				objectType.InvalidPicklistValues__c=ar1.get('Specialty_1_vod__c');
				objectType.Field_API_Name__c=ObjectAPIName;
				objectType.Object_API_Name__c=FieldAPIName;
                searchResults.add(objectType);            
                
				}            
			}
		
		}
		
		insert searchResults;
        return null;
}

Public static List<String> getPicklistValues(String Object_API_Name_vod__c,String Field_API_Name_vod__c){ 

			List<String> lstPickvals=new List<String>();
			Schema.SObjectType targetType = Schema.getGlobalDescribe().get(Object_API_Name_vod__c);//From the Object Api name retrieving the SObject
			Sobject Object_name = targetType.newSObject();
			Schema.sObjectType sobject_type = Object_name.getSObjectType(); //grab the sobject that was passed
			Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe(); //describe the sobject
			Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap(); //get a map of fields for the passed sobject
			List<Schema.PicklistEntry> pick_list_values = field_map.get(Field_API_Name_vod__c).getDescribe().getPickListValues(); //grab the list of picklist values for the passed field on the sobject
			for (Schema.PicklistEntry a : pick_list_values) { //for all values in the picklist list
			lstPickvals.add(a.getValue());//add the value  to our final list
		}

		return lstPickvals;
  
	} 


}

 
 In our application, TSF object is child object of Account object. We are creating the new records in two ways by dataload and system creation. 
Recently we found the TSF record names are having the Record Id(SFDC id). We are sure system won't create the records like that. But it's because of either dataload or user entered manunaly edited. Can you please advise how is it possible to update the records with record id. 

Record name is Text field, it's displaying the Record Id. It's not a custom page, also so there is no possible of vf page.  We are using either record id or external id for dataload. 
I have created the custom link which is linked to a dynamic report based on the record. When i used it , some of records / some profiles its showing Insufficient previllages error. A User is having same profile able to access. Can you please advise.
I need to write trigger to update the custom picklist name" Country__c" of Custom object call Medical__c from the "User' Object's custom field "market _c" Value. The Cusom object is having the custom field picklist "State_c " which dependent of " Country__c".

Please find below code is fetching the user's time off based on ownerid and user market. Some time we are getting the wrong datas like fetching the datas only based on the market. 

 

for(Working_Days__c wd : [select Id,User__c,Start_Date__c,End_Date__c,Expired__c,Market__c,RecordTypeId,Reason__c,Time__c,
M_AM__c,M_PM__c,Tu_AM__c,Tu_PM__c,W_AM__c,W_PM__c,
Th_AM__c,Th_PM__c,F_AM__c,F_PM__c,Sat_AM__c,Sat_PM__c,
Sun_AM__c,Sun_PM__c
from Working_Days__c
where Expired__c = false and (User__c = :ownerId or Market__c = :userMarket)  order by Time__c asc nulls last])

 

Expectation:

 

we are planning change the condition " where Expired__c = false and (User__c = :ownerId or (Market__c = :userMarket AND RecordTypeId= 'Company_Holdidays' "

 

But, we are facing problem in "  RecordTypeId= 'Company_Holdidays' " , please help me how to define and excute the same. 

I have created a Custom lookup field called User_Manager__c in User , I need to update manager field in user based the the custom field. Please advise how to proceed

 In our application, TSF object is child object of Account object. We are creating the new records in two ways by dataload and system creation. 
Recently we found the TSF record names are having the Record Id(SFDC id). We are sure system won't create the records like that. But it's because of either dataload or user entered manunaly edited. Can you please advise how is it possible to update the records with record id. 

Record name is Text field, it's displaying the Record Id. It's not a custom page, also so there is no possible of vf page.  We are using either record id or external id for dataload. 
I have created the custom link which is linked to a dynamic report based on the record. When i used it , some of records / some profiles its showing Insufficient previllages error. A User is having same profile able to access. Can you please advise.
I need to write trigger to update the custom picklist name" Country__c" of Custom object call Medical__c from the "User' Object's custom field "market _c" Value. The Cusom object is having the custom field picklist "State_c " which dependent of " Country__c".

Please find below code is fetching the user's time off based on ownerid and user market. Some time we are getting the wrong datas like fetching the datas only based on the market. 

 

for(Working_Days__c wd : [select Id,User__c,Start_Date__c,End_Date__c,Expired__c,Market__c,RecordTypeId,Reason__c,Time__c,
M_AM__c,M_PM__c,Tu_AM__c,Tu_PM__c,W_AM__c,W_PM__c,
Th_AM__c,Th_PM__c,F_AM__c,F_PM__c,Sat_AM__c,Sat_PM__c,
Sun_AM__c,Sun_PM__c
from Working_Days__c
where Expired__c = false and (User__c = :ownerId or Market__c = :userMarket)  order by Time__c asc nulls last])

 

Expectation:

 

we are planning change the condition " where Expired__c = false and (User__c = :ownerId or (Market__c = :userMarket AND RecordTypeId= 'Company_Holdidays' "

 

But, we are facing problem in "  RecordTypeId= 'Company_Holdidays' " , please help me how to define and excute the same. 

I have created a Custom lookup field called User_Manager__c in User , I need to update manager field in user based the the custom field. Please advise how to proceed