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

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 16
    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 want to integrate google hangouts/gmail chat in salesforce.  Can I any one help me how we can do this.

how to increase  code coverage for this class


Apex Class
@RestResource(urlMapping=‘/company/data’)

global class zoomdata {
    @HttpPost
    global static zoomdataResponse updatezoomdata(zoomdatawrapper zoomdata ){
        RestRequest req = RestContext.request;
        zoomdataResponse res = new zoomdataResponse();
        string message;
        res.lead_id =zoomdata.lead_id;
        list<lead> p1 =[Select id from lead where   Lead_ID__c =:zoomdata.lead_id  ];
        if(p1.size() ==0){
            res.error=true;
            res.message='zoomdata id does not exist';
       }
        else{
            try{
            lead pay = new lead();
            pay.Id= p1[0].id;
            if(string.isNotEmpty(string.valueof(zoomdata.zoom_parentemail)) )     
               pay.Zoom_TA_Parent__c=zoomdata.zoom_parentemail;
            
            
            if(string.isNotEmpty(string.valueof(zoomdata.zoom_tutoremail)))      
                pay.Zoom_TA_Tutor__c=zoomdata.zoom_tutoremail;
            
            if(string.isNotEmpty(zoomdata.Zoom_repemail))      
                pay.Zoom_TA_Rep__c=zoomdata.Zoom_repemail;
               
            if(string.isNotEmpty(string.valueof(zoomdata.zoom_studentemail)) )     
               pay.Zoom_TA_Student__c=zoomdata.zoom_studentemail;
            
            
            if(zoomdata.zoom_student_duration!=null)      
                pay.Zoom_TA_Student_Duration__c=zoomdata.zoom_student_duration;
                if(zoomdata.zoom_Parent_duration!=null)      
                pay.Zoom_TA_Parent_Duration__c=zoomdata.zoom_Parent_duration;
                if(zoomdata.zoom_Tutor_duration!=null)      
                pay.Zoom_TA_Tutor_Duration__c=zoomdata.zoom_Tutor_duration;
                if(zoomdata.zoom_Rep_duration!=null)      
                pay.Zoom_TA_Rep_Duration__c=zoomdata.zoom_Rep_duration;
                if(zoomdata.zoom_student_time!=null)      
                pay.Zoom_TA_Student_Login_Time__c=zoomdata.zoom_student_time;
                if(zoomdata.zoom_Parent_time!=null)      
                pay.Zoom_TA_Parent_Login_Time__c=zoomdata.zoom_Parent_time;
                if(zoomdata.zoom_Tutor_time!=null)      
                pay.Zoom_TA_Tutor_Login_Time__c=zoomdata.zoom_Tutor_time;
                if(zoomdata.zoom_Rep_time!=null)      
                pay.Zoom_TA_Rep_Login_Time__c=zoomdata.zoom_Rep_time;
            
                   update pay;
                  res.error=false;
            res.message ='zoomdata updated successfuly';
            }
            catch(exception e)
            {
                  res.error=true;
                res.message=e.getMessage();
            }
        }
        
        return res;
        
    }
    
}

Test class

@istest
Private class zoomdata_Test {
    @isTest
    static void validateZoomdata(){
        
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
       
        
        
       opportunity op = new opportunity();
        
        
        op.Name = 'testop';
        op.StageName = 'Converted';
        op.CloseDate = date.today();
        op.Zoom_TA_Student_Login_Time__c= Time.newInstance(0, 2, 2, 0);
         op.Zoom_TA_Parent_Login_Time__c=Time.newInstance(0, 2, 2, 0);
          op.Zoom_TA_Tutor_Login_Time__c=Time.newInstance(0, 2, 2, 0);
          op.Zoom_TA_Rep_Login_Time__c=Time.newInstance(0, 2, 2, 0);
        insert op;
        
        
      
       
        Opportunity pmt  =[Select id,Lead_Conversion_ID__c,Zoom_TA_Parent__c,Zoom_TA_Rep_Login_Time__c,Zoom_TA_Tutor_Login_Time__c,Zoom_TA_Parent_Login_Time__c,Zoom_TA_Student_Login_Time__c,Zoom_TA_Tutor__c,Zoom_TA_Rep__c,Zoom_TA_Tutor_Duration__c,Zoom_TA_Student__c,Zoom_TA_Student_Duration__c,Zoom_TA_Parent_Duration__c,Zoom_TA_Rep_Duration__c from Opportunity ];
        Zoomdatawrapper wrap=new Zoomdatawrapper();
       
          wrap.Zoom_repemail=pmt.Zoom_TA_Parent__c; 
          wrap.zoom_tutoremail=pmt.Zoom_TA_Tutor__c;
          wrap.zoom_parentemail=pmt.Zoom_TA_Rep__c;
          wrap.zoom_studentemail=pmt.Zoom_TA_Student__c; 
          if(pmt.Zoom_TA_Student_Duration__c!=null)  {
            wrap.zoom_student_duration=pmt.Zoom_TA_Student_Duration__c.intValue();
            }
            if(pmt.Zoom_TA_Parent_Duration__c!=null)  {
          wrap.zoom_Parent_duration=pmt.Zoom_TA_Parent_Duration__c.intValue();
          }
          if(pmt.Zoom_TA_Tutor_Duration__c!=null)  {
          wrap.zoom_Tutor_duration=pmt.Zoom_TA_Tutor_Duration__c.intValue(); 
          }
          if(pmt.Zoom_TA_Rep_Duration__c!=null)  {
            wrap.zoom_Rep_duration=pmt.Zoom_TA_Rep_Duration__c.intValue();
            }
          wrap.zoom_student_time=pmt.Zoom_TA_Student_Login_Time__c;
          wrap.zoom_Parent_time=pmt.Zoom_TA_Parent_Login_Time__c; 
          wrap.zoom_Tutor_time=pmt.Zoom_TA_Tutor_Login_Time__c;
          wrap.zoom_Rep_time=pmt.Zoom_TA_Rep_Login_Time__c;
          
          wrap.lead_id=pmt.Lead_Conversion_ID__c;
       
   
        
        Test.startTest();
        zoomdata.updatezoomdata(wrap);
        Test.stopTest();
    }
    
}

Please help me with this.
Can any one help test class for below trigger.


trigger AssignLeadsToQueue on Lead (before insert, before update){
    
  
  if (trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){

      
        List<Group> queues = [
                SELECT Id,
                    (Select Id, UserOrGroupId FROM GroupMembers Order By ID ASC)
                FROM Group
                Where Type = 'Queue'AND Name = 'High-Priority Leads'
        ];
   
        // Get the index of the last lead assigned user in the queue
        Lead_Round_Robin_Assignment__c lrr = Lead_Round_Robin_Assignment__c.getOrgDefaults();
        Integer userIndex = (lrr.get('User_Index__c') == null || Integer.valueOf(lrr.get('User_Index__c')) < -1) 
            ? -1 : Integer.valueOf(lrr.get('User_Index__c'));

        if (queues.size() > 0 && queues.get(0).GroupMembers.size() > 0) {
     
            Id queueId = queues.get(0).Id;
            Integer groupMemberSize = queues.get(0).GroupMembers.size();
            for (Lead l : Trigger.new) {
                if ((l.LeadSource =='Moengage'||l.LeadSource =='Facebook Ads'|') && l.Status== 'New'&&l.CreatedById=='********') {
                   system.debug('inside it is coming');
                    Integer leadUserIndex =  (userIndex + 1) >= groupMemberSize ? 0 : userIndex + 1;
                    l.OwnerId = queues.get(0).GroupMembers.get(leadUserIndex).UserOrGroupId;
                    userIndex = leadUserIndex;
                }
            }

            // Update the custom settings user index with the last lead assigned user
            lrr.User_Index__c = userIndex;
            update lrr;
        }
    }

}
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.

Hi,

I want to integrate google hangouts/gmail chat in salesforce.  Can I any one help me how we can do this.

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