• FaridKognoz
  • NEWBIE
  • 30 Points
  • Member since 2009

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 17
    Replies

Is there any way to determine if a custom field is required in Apex (not through Force.com API)?

 

 

I couldn't find any way - dynamic Apex is of no value/help.

 

 

 

Thanks!

Hi all;

 

I'm trying to get metadata  information from specific objects and fields.

For example the field type for "Account.AccountNumber" should retrieve "Text(40)".

I know how to do it with apex but I want to do it in Java using the metadata API. I am looking at the documentation for this API and I can't find any straightforward method for getting this info.

Is it correct the way I am trying to do this? (I mean using the metadata API?).

In case it is, is there a simple way to get this kind of information?

 

Thanks;

 

Farid

I'm trying to get  the server url in apex code to pass it (and the sessionId) to a web service outside salesforce to make API calls. I've read this post and changedthe visualforce parameter to "$Api.Enterprise_Server_URL_180" but this is giving me the following url: https://c.na7.visual.force.com/services/Soap/c/18.0/{ORGId}.

 

There is no way I can access the api with that url, it should be something like:

https://na7-api.salesforce.com/services/Soap/c/18.0/{ORGId}

 

So is there a way to get the real serverURL? Or am I supposed to parse that first url to create the second one? (This wouldn't be very elegant).

 

Thanks in advance;

 

Farid

I've created a tool on PERL that creates a csv file with the following information regarding a force.com project:

 

Page Name, Page Controller, Component, Component Controller, Component inside Component, Comp Controller.

 

In order to use it you just need the  source code and execute the following line from the comand line

 (asuming you save the file as status.pl):

 

perl status.pl "PathToSRCDir" >outputfile.csv

 

for example:

perl status.pl "c:\Documents and Settings\Use\workspace\someproject\src"  > output.csv

 

If you open the CSV from excel or google spreadsheet you will have the information
for all the pages in the project, their controllers and each of the components they have, also if the components have components inside they will be listed.

I think this could be a useful tool for force.com sites projects.

Bellow is the source code (just save it on your disk and run it).

 

 

 

 

 

$dirname = @ARGV[0]; $classesDir = $dirname."\classes"; $pagesDir = $dirname."\\pages"; $componentsDir = $dirname."\\components"; #print "$pagesDir\n"; my %compController = (); my %componentComponents = (); my %pagesComponents = (); my %pageController = (); opendir(DIR, $componentsDir) or die "can't opendir $dirname: $!"; while (defined($file = readdir(DIR))) { # do something with "$dirname/$file" $filepath = $componentsDir."\\".$file; #print $filepath."\n"; if($file ne "." && $file ne ".."){ open FILE, "<", $filepath or die $!; @farid = <FILE>; $todo = ""; foreach(@farid){ $todo=$todo.$_; } $_ = $todo; @pageTag = /<apex:component .*?>/gmsi; @componentTags = /<c:.*?>/gmsi; foreach(@pageTag){ #print $_."\n"; #$pageController{$file} $thestring = $_; if($thestring =~ m/controller="([^ >]*?)"/i) { $compController{$file}=$1; } #print $_; } foreach(@componentTags){ #print "$_\n"; $thestring = $_; #print $thestring; #if($thestring =~ m/(.*?)/i) { if($thestring =~ m/<c:([^ \/]*)/i) { $nomComponente = $1.".component"; if($componentComponents{$file} eq ""){ $componentComponents{$file} = $1; } else{ $componentComponents{$file} = $componentComponents{$file}.":".$1; } } } } #<apex:page showHeader="false" standardStylesheets="false" sidebar="false"> } closedir(DIR); opendir(DIR, $pagesDir) or die "can't opendir $dirname: $!"; while (defined($file = readdir(DIR))) { # do something with "$dirname/$file" $filepath = $pagesDir."\\".$file; #print $filepath."\n"; if($file ne "." && $file ne ".."){ open FILE, "<", $filepath or die $!; @farid = <FILE>; $todo = ""; foreach(@farid){ $todo=$todo.$_; } $_ = $todo; @pageTag = /<apex:page .*?>/gmsi; @componentTags = /<c:.*?>/gmsi; foreach(@pageTag){ $thestring = $_; if($thestring =~ m/controller="([^ >]*?)"/i) { $pageController{$file}=$1; } if($thestring =~ m/extensions="([^ >]*?)"/i) { $pageController{$file}=$1; } #print $_; } foreach(@componentTags){ #print "$_\n"; $thestring = $_; #print $thestring; #if($thestring =~ m/(.*?)/i) { if($thestring =~ m/<c:([^ \/]*)/i) { $nomComponente = $1.".component"; if($pagesComponents{$file} ne ""){ @temp = ($1); $pagesComponents{$file} = $pagesComponents{$file}.":".$1; } else{ $pagesComponents{$file} = $1; } } } } #<apex:page showHeader="false" standardStylesheets="false" sidebar="false"> } closedir(DIR); print "NOMBRE PAGINA,CONTROLADOR PAGINA,NOMBRE COMPONENTE,CONTROLADOR COMPONENTE, COMPONENTE INSIDE, CONTROLADOR COMPONENTE\n"; @pages = (); foreach my $llave (keys %pagesComponents){ push(@pages,$llave); } @pages = sort(@pages); foreach my $llave (@pages){ print "$llave,"; if($pageController{$llave} ne ""){ print "$pageController{$llave},,,,\n"; } else{ print",,,,,\n"; } if($pagesComponents{$llave} ne ""){ @pageComponent = split(/:/,$pagesComponents{$llave}); foreach $component (@pageComponent){ print ",,".$component.","; $nomComponente = $component.".component"; if($compController{$nomComponente} ne ""){ print $compController{$nomComponente}.",,\n"; } else{ print",,,\n"; } if($componentComponents{$nomComponente} ne ""){ @components = split(/:/,$componentComponents{$nomComponente}); foreach $compcomp (@components){ $nomCompComp = $compcomp.".component"; print ",,,,".$nomCompComp.","; if($compController{$nomCompComp} ne ""){ print $compController{$nomCompComp}."\n"; } else{ print",\n"; } } } } } else{ print ",,,\n"; } }

 

 

 

I've been searching for a way to access the API on a salesforce account but found on this article that is not possible:

 

If you want to publish your composite or client app to AppExchange, you can request during the Security Review a clientID that you can include in your SOAP headers, allowing you API access to Professional Edition customers. [..]

Note: Group Edition does not allow API support even with the use of a partner clientID.

 

On the other hand I've tested an application from Appirio that connects the google cloud with salesforce, and it is able to create contacts from an external application on a group edition that doesn't have API access. How is this possible? Do they have special permissions? Or I'm missing something?

 

Thanks in advance.

 

 Farid

I'm writing an apex webservice. How should I return a soap fault?

Thanks in advance;

 

Farid

Message Edited by FaridKognoz on 11-13-2009 06:47 AM

Hi;

I want to use count() on an soql query. When there are more than 10.000 records, an apex exception is trown "To many query rows". Is it not possible to count more than 10.000 records?

Thanks,

 

I'm trying to make a VF page listing records using the StandardSetController.The problem I have is when dealing with more than 10 thousand records (I get an exception from the SetController). Is there a way to paginate records when the total amount of records is more than 10000? When using standard salesforce views for the object I see there are no problems with it so there has to be a way.

Thanks;

 

Farid

Hello;

I try to pre populate the "new contract" fields using this post: https://na6.salesforce.com/secur/forgotpassword.jsp?r=F0j6FwEhch5yAH5YV_T_3ArID6fs0T.iZQby4uyjseu93wK2_bIiNgdnh_t12R67

 

Basically what I did:

 

 

A visualforce page with this line only:

 

<apex:page standardController="Task" extensions="CustomEditContract" action="{!doCreate}"/>

 

 

And and apex class (CustomEditContract):

 

public class CustomEditContract { public CustomEditContract(ApexPages.StandardController controller) { } public PageReference doEdit() { /* Get the pagereference for the contract edit */ Contact contr = new Contact(); ApexPages.StandardController theC= new ApexPages.standardController(contr); PageReference p = theC.edit(); return p; } }

 The problem is that the edit() doesn't accepts an object without an ID.

I don't want to use S-controls or building the entire page using visualforce, but I didn't found any other solutions.

So, is there no way of pre populating a new object using apex and the StandardController?

 

Thanks;

Farid

 

I have a visualforce page with two different outputPanels separeted from each other. Panel Nº1 has some commandLinks that rerender Panel 1 & 2. When clicking on one of those commandLinks Panel 1 rerenders as it should but, instead of panel 2 beeing rerenderd a copy of this Panel is rendered below Panel 1. Both panels are entirely different. If I change the rerender statement to just rerender one of the panels (just one) it works fine no matter which panel I rerender but when rerendering both this issue comes again.

Is this a known bug?

Thanks;

Farid

 

I tryed using the apex:PageMessages component to show custom errors but this component is always showing warings like "The element type "body" should be terminated by the matching end-tag "</body>".I ripped apart the hole page leaving just the tags html, head & body with their correspondant ending tags in it but the warning was still there(randomly).

Shouldn't I use this component (Page Messages)? Or is there something I'm not seeing?

Thanks;

Farid

 

 

I found out that when I "rerender" some part of the page, all the getters execute, not just the getters from variables within the rerender part of the page. Could I control this? How?

This is the scenario: I have a page controller using a variable with the same name as a variable in a component's controller. I use the component in the same page and realised this was a problem. I assume that in execution time, all the apex code es concatenated (page controller & components controllers). I realize that changing the name of one of the variables would solve the problem but What would be the correct thing to do?

Thanks in advance

I'm using c# to code a listener for outbound messages. When using the sessionId and EnterpriseUrl (from the outbound message) with the sforce api I have no problems accesing data in salesforce, but when traying to use the metadata api it says "No operation available for request".

Is there a way to use the metadata API with the sessionId and Enterprise Url provided in the outbound message?

Thanks;

Hi all;

 

I'm trying to get metadata  information from specific objects and fields.

For example the field type for "Account.AccountNumber" should retrieve "Text(40)".

I know how to do it with apex but I want to do it in Java using the metadata API. I am looking at the documentation for this API and I can't find any straightforward method for getting this info.

Is it correct the way I am trying to do this? (I mean using the metadata API?).

In case it is, is there a simple way to get this kind of information?

 

Thanks;

 

Farid

I need to create a trigger that will insert new records, but I cannot use a DML insert statement to create new records on the object that is firing the trigger.

 

Is there an alternative?  Some other method to accomplish this?

 

Here is a stripped down prototype of what I'm trying to do:

 

trigger FullfillmentGetAccountHierarchy on Fulfillment__c (before insert) { // Other code occurs here to get the values dynamically for the hard-coded values below List<Fulfillment__c> fuls = new List<Fulfillment__c>(); for (Integer i = 0; i < 6; i++) { Fulfillment__c ful = new Fulfillment__c(); ful.Contact__c = '003S0000006owfN'; ful.Account__c = '001S000000AUd0r'; ful.Fulfillment_Request__c = 'a0AS000000214OJ'; fuls.add(ful); } insert(fuls); }

Is there any way to insert new records using a trigger on the object that fires the trigger?  Any suggestions? 

 

Thanks.

Message Edited by bohemianguy100 on 03-04-2010 08:47 AM
Hi all;
  Is there a way to create a new field in a sObject by using Apex code.
  For an example I want to create a field named "OpportunityNumber" at run time.
  
 
I want something similar to following code.
  
  Opportunity.createNewField('OpportunityNumber'); 

I've been searching for a way to access the API on a salesforce account but found on this article that is not possible:

 

If you want to publish your composite or client app to AppExchange, you can request during the Security Review a clientID that you can include in your SOAP headers, allowing you API access to Professional Edition customers. [..]

Note: Group Edition does not allow API support even with the use of a partner clientID.

 

On the other hand I've tested an application from Appirio that connects the google cloud with salesforce, and it is able to create contacts from an external application on a group edition that doesn't have API access. How is this possible? Do they have special permissions? Or I'm missing something?

 

Thanks in advance.

 

 Farid

Hi all,

 

I have the following bit of code:

 

integer queryRowLimit = Limits.getLimitQueryRows(); if (queryRowLimit==500) { // if row limit is 500, it means we are in a test method. queryRowLimit=100; } for (List<Contract_Line_v2__c> cl2List : [select id from Contract_Line_v2__c limit :queryRowLimit]) { // do some stuff here }

 

When it runs I am getting a 'Too Many Query Rows: 10001' error. However, Apex Explorer tells me that there are only 7452 rows in that object.

 

Am I using the correct format for the SOQL for loop? I can't work out why it is returning 10000+ results.

 

Thanks,

 

Andy

 

Hi,

 

In one of my controller classes I need to retrieve Created By Name field from a custom object.

 

I am running

 

String queryString = 'Select id, File_Name__c, CreatedById, CreatedBy.Name, CreatedDate from ...';

 

Querying the custom object and putting fields in a list:

 

List<SObject> myList = Database.query(queryString);

 

Then trying to set the created by name to a wrapper class field in a loop over myList:

 

w.setCreatedByName((String)f.get('CreatedBy.Name'));

 

But it is giving me

 

Invalid field CreatedBy.Name for XYZ__c

 

What might be the problem. How can I retrieve CreatedBy.Name. I can retrieve CreatedById directly but it is not solving my problem.

 

Thanks...

I'm trying to make a VF page listing records using the StandardSetController.The problem I have is when dealing with more than 10 thousand records (I get an exception from the SetController). Is there a way to paginate records when the total amount of records is more than 10000? When using standard salesforce views for the object I see there are no problems with it so there has to be a way.

Thanks;

 

Farid

Hello,

 

Maybe I missed something, but I'm having trouble finding which fields are required based on the results of a describeSObjectResult.  I've tried searching through the documentation and other postings, but did not come up with much information.

 

What I'm trying to do is loop through the list of fields for a particular object (chosen at run-time) and mark each required field.  Unfortunately, it doesn't appear that the the Field objects found in the DescribeSObjectResult object have an "isRequired" method to easily tell.  I tried to cobble something together, assuming that if isNillable and isDefaultedOnCreate were both false, then it was required, but this doesn't appear to be completely accurate.

 

I would appreciate any help.  Perhaps I'm missing something or there is another approach that I can take. Thanks!

  • May 29, 2009
  • Like
  • 0

Is there any way to determine if a custom field is required in Apex (not through Force.com API)?

 

 

I couldn't find any way - dynamic Apex is of no value/help.

 

 

 

Thanks!

I have a visualforce page with two different outputPanels separeted from each other. Panel Nº1 has some commandLinks that rerender Panel 1 & 2. When clicking on one of those commandLinks Panel 1 rerenders as it should but, instead of panel 2 beeing rerenderd a copy of this Panel is rendered below Panel 1. Both panels are entirely different. If I change the rerender statement to just rerender one of the panels (just one) it works fine no matter which panel I rerender but when rerendering both this issue comes again.

Is this a known bug?

Thanks;

Farid

 

I tryed using the apex:PageMessages component to show custom errors but this component is always showing warings like "The element type "body" should be terminated by the matching end-tag "</body>".I ripped apart the hole page leaving just the tags html, head & body with their correspondant ending tags in it but the warning was still there(randomly).

Shouldn't I use this component (Page Messages)? Or is there something I'm not seeing?

Thanks;

Farid

 

 

I'm using c# to code a listener for outbound messages. When using the sessionId and EnterpriseUrl (from the outbound message) with the sforce api I have no problems accesing data in salesforce, but when traying to use the metadata api it says "No operation available for request".

Is there a way to use the metadata API with the sessionId and Enterprise Url provided in the outbound message?

Thanks;

How do I auto populate a custom field (pick list) at the Opportunity Product line-item level based on the product that is selected.  That is, when I "Add Product" to an Opportunity, I would like two fields at the line item level to be already pre selected.  How would I go about accomplishing this?  I am using the professional edition.
Message Edited by Slideumentary on 02-23-2009 08:22 AM
Hi, i'm trying to POST a .doc file using the HTTPRequest Class. The file is taken from a mail attachment (blob variable). The request can send ASCII files but when it comes to binary data it doesn't work.
As for the request's body, I'm using a multipart form, the only problem I'm having is when adding the blob file to it. I tried EncodingUtil.Base64Encode and convertToHex... non of them worked.
Am I missing something here?
Any help would be apreciated;
Thanks
Farid