• K Srikanth
  • NEWBIE
  • 35 Points
  • Member since 2018
  • Salesforce Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 15
    Replies
VF Page:
<apex:page controller="FLSController2">
    <apex:form >
        <apex:pageBlock title="FLS Test" >
            <apex:inlineEditSupport event="onDblClick"/>
            <apex:pageMessages />
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column headerValue="Account Name" value="{!a['Name']}" rendered="{!$ObjectType.Account.Fields.Name.Accessible}"/>
                <apex:column headerValue="Phone" value="{!a['Phone']}" rendered="{!$ObjectType.Account.Fields.Phone.Accessible}"/>
                <apex:column headerValue="Industry" value="{!a['Industry']}" rendered="{!$ObjectType.Account.Fields.Industry.Accessible}"/>
                <apex:column headerValue="Rating" value="{!a['Rating']}" rendered="{!$ObjectType.Account.Fields.Rating.Accessible}"/>
                <apex:column headerValue="Type" value="{!a['Type']}" rendered="{!$ObjectType.Account.Fields.Type.Accessible}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Controller:
public with sharing class FLSController2 {
	
    public List<Map<String, String>> acc;
    
    public FLSController2(){
       acc = new List<Map<String, String>>();
    }
    
    public List<Map<String, String>> getacc(){
    
    	List<Account> aList = [SELECT Name, Industry, Phone, Rating, Type FROM Account];
        for(Account a: aList){
            Map<String, String> m = new Map<String, String>();
            m.put('Name', a.Name);
            m.put('Industry', a.Industry);
            m.put('Phone', a.Phone);
            m.put('Rating', a.Rating);
            m.put('Type', a.Type);
            acc.add(m);
        }
        return acc;
    }
}

Error:
User-added image
Hi ,

I need to import the data from third party application to salesforce, with Single sign on. 
Can any one help me to understand the steps to complete this.

I have custom picklist field listview__c and it has picklist values like(listview-001,listview-002,....,listview-500) upto 500. My requirement is if picklist value listview-001 is used, then I should not use that value. I want to know till how many picklist values have been used.

Can any one help for this?
Thankyou

Hello,

Can we get admin user session id in apex?
Hello,

How can we give FLS edit access to custom standard profiles. I have a requirement custom profiles can give edit access to fields. 
I am getting below error, is there any workaround for this.User-added image
Thankyou
Hi,

I have a requirement to find nearest lead record for all account records, I can  find the distance and sort the disance.

But I am facing issue to query two object all records in bactch apex. Is there any best way to complete this.

Thanks in advance.
 

Hi,

I am creating a custom field using apex metadata api call for Standard user (non admin) profiles. But not able to give edit access for below code.

 String strRequestBody1 = '<?xml version="1.0" encoding="UTF-8"?>'
                + '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
                + '<soapenv:Header>'
                + '<ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">'
                + '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>'
                + '</ns1:SessionHeader>'
                + '</soapenv:Header>'
                + '<soapenv:Body>'
                + '<upsertMetadata xmlns="http://soap.sforce.com/2006/04/metadata">'
                + '<metadata xsi:type="ns2:Profile" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">'
                + '<fullName>Standard</fullName>'
                + '<custom>false</custom>'
                + '<fieldPermissions>'
                + '<field>'+strObjectName + '.' +strField2API+' </field>'
                + '<editable>true</editable>'
                + '</fieldPermissions>'
                + '</metadata>'
                + '</upsertMetadata>'
                + '</soapenv:Body>'
                + '</soapenv:Envelope>';
    
                HTTP httpService1 = new HTTP();
                HTTPRequest request1 = new HTTPRequest();
                request1.setMethod('POST');
                request1.setHeader('Content-Type', 'text/xml');
                request1.setHeader('SOAPAction', 'upsertMetadata');
                request1.setBody(strRequestBody1);
                request1.setCompressed(false);
                request1.setEndpoint(ENDPOINT_URL);
                
                if(!Test.isRunningTest()) {
                    HTTPResponse response1 = httpService.send(request1);
                    System.debug('Response ::: '+response1.getBody());
                }

I am getting error ==> 
Admin.userCanEditFieldPermissions</message><statusCode>INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY</statusCode></errors><fullName>Admin

Can anyone help me to fix this for standard user how to give edit access for field using apex

Hi ,

Can any one help me what are the key points should cover in solution architecture and usage document in new security review submission.
Hi,
Can anyone help with test class for below methods.

@RemoteAction
public static String Createcfield(String ObjectName,List<id> recordids) {
Map<String, Schema.SObjectField> fieldMap;
fieldMap = Schema.getGlobalDescribe().get(ObjectName).getDescribe().fields.getMap();
Blob blobKey = crypto.generateAesKey(128);
String key = EncodingUtil.convertToHex(blobKey);
String uniq = key.substring(0,4);
String cField='PVListviewFiled'+uniq+'__c';
HTTP httpService = new HTTP();
HTTPRequest request = new HTTPRequest();
pvMetadataService.MetadataPort metadataservice = new pvMetadataService.MetadataPort();
metadataservice.SessionHeader = new pvMetadataService.SessionHeader_element();
metadataservice.SessionHeader.sessionId = UserInfo.getSessionId();
PVMetadataService.CustomField customField = new PVMetadataService.CustomField();
customField.fullName = ObjectName+'.'+ cField;
customField.label = cField.replace('__c','');
customField.defaultvalue = 'false';
customField.type_x = 'Checkbox';
List<PVMetadataService.Metadata> fields = new List<PVMetadataService.Metadata>();
fields.add(CustomField);
list<pvMetadataService.SaveResult> results =MetadataService.createMetadata(fields);
string strObjectName = ObjectName;
string strField2API= cField;
if(results[0].success) {
String strRequestBody1 = '<?xml version="1.0" encoding="UTF-8"?>'
+ '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
+ '<soapenv:Header>'
+ '<ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">'
+ '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>'
+ '</ns1:SessionHeader>'
+ '</soapenv:Header>'
+ '<soapenv:Body>'
+ '<upsertMetadata xmlns="http://soap.sforce.com/2006/04/metadata">'
+ '<metadata xsi:type="ns2:Profile" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">'
+ '<fullName>Admin</fullName>'
+ '<custom>false</custom>'
+ '<fieldPermissions>'
+ '<field>'+strObjectName + '.' +strField2API+' </field>'
+ '<editable>true</editable>'
+ '</fieldPermissions>'
+ '</metadata>'
+ '</upsertMetadata>'
+ '</soapenv:Body>'
+ '</soapenv:Envelope>';
HTTP httpService1 = new HTTP();
HTTPRequest request1 = new HTTPRequest();
request1.setMethod('POST');
request1.setHeader('Content-Type', 'text/xml');
request1.setHeader('SOAPAction', 'upsertMetadata');
request1.setBody(strRequestBody1);
request1.setCompressed(false);
request1.setEndpoint(ENDPOINT_URL);
if(!Test.isRunningTest()) {
HTTPResponse response1 = httpService.send(request1);
System.debug('Response ::: '+response1.getBody());
}}
updaterecord(ObjectName,recordids,cField);
return cField;
}
@future(Callout=true)
public static void updaterecord(String ObjectName,List<id> recordids,string cField){
List<id> Updateids = recordids;
List<sObject> recordsToUpdate = new List<sObject>();
string objname=ObjectName;
for(id str:Updateids){
Sobject record;
sObject sRecord = Schema.getGlobalDescribe().get(objname).newSObject() ;
sRecord.put('Id',Str);
sRecord.put(cField, True);
recordsToUpdate.add(sRecord);
}
update recordsToUpdate;
}
@RemoteAction
public static List<String> Createlistviewfield(String ObjectName, String CFieldName, String ListViewName) {
string failedmesg='';
string finalurl='';
pvMetadataService.MetadataPort metadataservice = new pvMetadataService.MetadataPort();
metadataservice.SessionHeader = new pvMetadataService.SessionHeader_element();
metadataservice.SessionHeader.sessionId = UserInfo.getSessionId();
pvMetadataService.ListViewFilter filter = new pvMetadataService.ListViewFilter();
filter.field=CFieldName;
filter.operation = 'equals' ;
filter.value='1';
system.debug(ObjectName+'.'+ListViewName);
pvMetadataService.ListView listView = new pvMetadataService.ListView();
listView.fullName = ObjectName+'.'+ListViewName.replace(' ','_');
listView.label = ListViewName;
listView.filterScope = 'Everything';
listView.filters= new list<pvMetadataService.ListViewFilter>{filter};
list<pvMetadataService.Metadata> fieldsabc = new list<pvMetadataService.Metadata>();
system.debug(listView.fullName);
fieldsabc.add(listView);
List<pvMetadataService.SaveResult> resultss = MetadataService.createMetadata(fieldsabc);
list<PVMetadataService.Error> ermsg = new list<PVMetadataService.Error>();
if(!resultss[0].success){
ermsg=resultss[0].errors;
failedmesg+=ermsg[0].message;
}
Schema.SObjectType objType = Schema.getGlobalDescribe().get(objectName);
Schema.DescribeSObjectResult r = objType.getDescribe();
String keyPrefix = r.getKeyPrefix();
if(resultss[0].success){
listview displaylistview= [SELECT Id,Name,Sobjecttype FROM listview WHERE Name=:ListViewName AND Sobjecttype =: ObjectName ];
finalurl+=URL.getSalesforceBaseUrl().toExternalForm() +'/'+keyPrefix+'?fcf='+String.valueOf(displaylistview.id).substring(0, 15);
}
List<String> resultmsg= new List<String>{failedmesg,String.valueOf(resultss[0].success),finalurl};
return resultmsg;
}
Hi,

Is there any way to hide custom tabs using APEX?
 
Hi,

I have a requriment to create list view from VF page.

Is there any way to create listview from apex
Hi ,

Can any one help to get URL for   activities in lightining. 


Thanks in advance.
Hello,

Can we get admin user session id in apex?
Hello,

How can we give FLS edit access to custom standard profiles. I have a requirement custom profiles can give edit access to fields. 
I am getting below error, is there any workaround for this.User-added image
Thankyou
Hi,

I have a requirement to find nearest lead record for all account records, I can  find the distance and sort the disance.

But I am facing issue to query two object all records in bactch apex. Is there any best way to complete this.

Thanks in advance.
 

Hi,

I am creating a custom field using apex metadata api call for Standard user (non admin) profiles. But not able to give edit access for below code.

 String strRequestBody1 = '<?xml version="1.0" encoding="UTF-8"?>'
                + '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
                + '<soapenv:Header>'
                + '<ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">'
                + '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>'
                + '</ns1:SessionHeader>'
                + '</soapenv:Header>'
                + '<soapenv:Body>'
                + '<upsertMetadata xmlns="http://soap.sforce.com/2006/04/metadata">'
                + '<metadata xsi:type="ns2:Profile" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">'
                + '<fullName>Standard</fullName>'
                + '<custom>false</custom>'
                + '<fieldPermissions>'
                + '<field>'+strObjectName + '.' +strField2API+' </field>'
                + '<editable>true</editable>'
                + '</fieldPermissions>'
                + '</metadata>'
                + '</upsertMetadata>'
                + '</soapenv:Body>'
                + '</soapenv:Envelope>';
    
                HTTP httpService1 = new HTTP();
                HTTPRequest request1 = new HTTPRequest();
                request1.setMethod('POST');
                request1.setHeader('Content-Type', 'text/xml');
                request1.setHeader('SOAPAction', 'upsertMetadata');
                request1.setBody(strRequestBody1);
                request1.setCompressed(false);
                request1.setEndpoint(ENDPOINT_URL);
                
                if(!Test.isRunningTest()) {
                    HTTPResponse response1 = httpService.send(request1);
                    System.debug('Response ::: '+response1.getBody());
                }

I am getting error ==> 
Admin.userCanEditFieldPermissions</message><statusCode>INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY</statusCode></errors><fullName>Admin

Can anyone help me to fix this for standard user how to give edit access for field using apex

Hi,

Is there any way to hide custom tabs using APEX?
 
Hi,

I have a requriment to create list view from VF page.

Is there any way to create listview from apex
Hi ,

Can any one help to get URL for   activities in lightining. 


Thanks in advance.
VF Page:
<apex:page controller="FLSController2">
    <apex:form >
        <apex:pageBlock title="FLS Test" >
            <apex:inlineEditSupport event="onDblClick"/>
            <apex:pageMessages />
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column headerValue="Account Name" value="{!a['Name']}" rendered="{!$ObjectType.Account.Fields.Name.Accessible}"/>
                <apex:column headerValue="Phone" value="{!a['Phone']}" rendered="{!$ObjectType.Account.Fields.Phone.Accessible}"/>
                <apex:column headerValue="Industry" value="{!a['Industry']}" rendered="{!$ObjectType.Account.Fields.Industry.Accessible}"/>
                <apex:column headerValue="Rating" value="{!a['Rating']}" rendered="{!$ObjectType.Account.Fields.Rating.Accessible}"/>
                <apex:column headerValue="Type" value="{!a['Type']}" rendered="{!$ObjectType.Account.Fields.Type.Accessible}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Controller:
public with sharing class FLSController2 {
	
    public List<Map<String, String>> acc;
    
    public FLSController2(){
       acc = new List<Map<String, String>>();
    }
    
    public List<Map<String, String>> getacc(){
    
    	List<Account> aList = [SELECT Name, Industry, Phone, Rating, Type FROM Account];
        for(Account a: aList){
            Map<String, String> m = new Map<String, String>();
            m.put('Name', a.Name);
            m.put('Industry', a.Industry);
            m.put('Phone', a.Phone);
            m.put('Rating', a.Rating);
            m.put('Type', a.Type);
            acc.add(m);
        }
        return acc;
    }
}

Error:
User-added image

Can we display the text in the field in the below format 

https:\\www.xero.com.au/wp-content/8.53-AM.PNG,
https:\\www.xero.com.au/wp-content/8.54-AM.PNG,
https:\\www.xero.com.au/wp-content/8.53-AM.PNG

currently, its displayed as 


https:\\www.xero.com.au/wp-content/8.53-AM.PNG,https:\\www.xero.com.au/wp-content/8.54-AM.PNG,https:\\www.xero.com.au/wp-content/8.53-AM.PNG]

So, i want to insert a line feed and remove , and also ]

Please advise. Whether I need a apex trigger or a formula or a validation can help here.  


 
We've successfully added a number of Custom Fields using the Metadata API.  Our site is an Asp.net and we're using VB for coding (thought about posting to .NET Development, but our question is more API focused).  First we build a Custom Field: 
metaCustomField = New sfMetadata.CustomField
metaCustomField.fullName = "Account.TestField__c"
metaCustomField.description = "Test Field for Account"
metaCustomField.inlineHelpText = "Test Field for Account"
metaCustomField.label = "Field Label"
metaCustomField.length = 20
metaCustomField.lengthSpecified = True
metaCustomField.unique = False
Then we add the Custom Field to an Array of Custom Fields (metaCustomFields).  There are roughly 40 fields, so we limit the array to 10 and submit each batch of 10 fields using:
metaCustomFieldsResult = myMetaService.create(metaCustomFields)
This all works well, and the fields are created as desired.  The first time we created the fields, it worked perfectly and we were then able to use the Soap API to populate the Account object with data (including the custom fields).

However, for some reason, if we delete a Custom Field and then add it again, or if we test using other Salesforce logins, the fields are getting generated properly, but the permissions on the fields are no longer being set (none of the "Field-Level Security" is set to visible).  We're not sure what we changed, but we've begun looking into how to apply Permission Sets to the Custom Fields for the Account object.  There appears to be a couple concepts to consider.  First, we've seen some code for building a package.xml file listing our field permissions and then submitting the zipfile:
<fieldPermissions>
     <editable>true</editable>
     <readable>true</readable>
     <field>Account.TestField__c</field>
</fieldPermissions>
In addition, we noticed that there are some additional Metadata API functions that look like they might help, but we can't find any details or code samples on how to apply them:
' Will adding either of these lines to the
' Custom field definition help:
metaCustomField.visibleLines = 1
metaCustomField.writeRequiresMasterRead = True

' Or, define a Permission Set
metaFieldPermission = New sfMetadata.PermissionSet
' Not sure what to do with it from here...

Can anyone tell us if we are heading in the right direction, or if there is a preferred method for setting the "Visible" Field-Level Security permissions for the custom fields we have created?

  • May 23, 2014
  • Like
  • 0