• canonw
  • NEWBIE
  • 54 Points
  • Member since 2008

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 46
    Replies
We are trying to do a trigger to calculate the amount in USD and store in a custom field in Opportunity. But I am facing the NullPointerException

Code:
trigger opptyAmountNusd on Opportunity (after update) {
//Calculates the USD equivalent and updates in another field

if (Trigger.isUpdate) {
    //for (Opportunity o_oppty : Trigger.old) {
   
    Opportunity[] opps = new List<Opportunity>();
        for (Opportunity n_oppty : Trigger.new) {
            Opportunity opp_tmp = n_oppty;
           
            if ((n_oppty.Amount != 0) ||(n_oppty.Amount != NULL) ) {
                    Decimal a = n_oppty.Amount;
                    String c = n_oppty.CurrencyIsoCode.substring(0,3);
                   
                    CurrencyType ct = [Select ConversionRate from CurrencyType where IsoCode=:c limit 1][0];
           
                    Decimal cr = ct.ConversionRate;
                   
                    opp_tmp.Amount_In_USD__c = cr*a;
                    opps.add(opp_tmp);
                   
                    //n_oppty.Amount_In_USD__c = cr*a;      
            }
        }
    //}
   
     for (Opportunity opp_tmp : opps) {
    
         update opp_tmp;
     }
}



}

Message Edited by rob_ocp on 07-10-2008 11:08 AM

Message Edited by rob_ocp on 07-10-2008 11:11 AM
In my custom controller for a Visualforce page, I'm dynamically building a URL to an external vendor site that looks something like this in my sandbox:
 
Code:
externalURL + '—id=' + objectId + '&sessionid=' + mySessionId + '&url=https://tapp0-api.salesforce.com/services/Soap/class/my_Web_Service'

 
For this, the externalURL is something like https://thevendor.urlhere.com.  Of course, objectId is my Salesforce object and mySessionId is my Salesforce session so the vendor can connect to my webservice.
Once I build the URL, I want to open it in a new window (like target="_blank" for a hyperlink), leaving the original Visualforce page open in the Salesforce window.
 
I have the basic functionality working using a Redirect, but I've been unable to determine how to open it in a new window instead of overlaying the page in the existing one.
 
Hi everyone.  

   Is there a Apex class method to get current Salesforce.com instance or URL at runtime?

I want to generate hyperlinks like https://na4.salesforce.com/{accountId} in code.  But I don't want to hard code 'na4'.

Every time I deploy the same code back to Sandbox, I must fix the instance manually.

Thanks in advance.


  • August 04, 2008
  • Like
  • 0
I have to following code snippet

Code:
<apex:column ... >
{!IF(ISNULL(var.Name), "&nbsp;", var.Name)}
</apex:column>


This block does not generate &nbsp; as expected.  Instead, it renders &#160; instead. 

Does anyone know the proper coding to render &nbsp;? 


Thanks in advance.
I read Visualforce Developer's Guide for Spring 08. 

It documents Custom Component does not allow executing SOQL or SOQL queries or DML operations. 

Is that remains the case for Summer 08?

Thanks in advance.
Does anyone know how to get date format for current user in scontrol?

The reason for date format is date picker. When I assign a date value to date picker, it must be locale oriented. Otherwise, s-control may assign date as DD/MM/YYY, instead of MM/DD/YYYY.

I know UserContext.dateFormat is the right variable.  But I can't find the method to get the value.  We have users around the world using several locale. So, hardcode is not an option.

Thanks in advance

I wonder if this is doable. I have the following code snippet in scontrol

Code:
<script language="JavaScript"> 

function refresh() {

// How to replace hard-code value with a lookup function?
var someCustomField = '00N60000001Wksv';

window.opener.location="/001/e—retURL=%2F001%2Fo&RecordType=0123000000007cT&" + someCustomField + "=2";
}

refresh();
</script>
 
Is there a function to lookup a particular custom field in a form?

Here's my siutation.  I create a custom field in sandbox.  Obviously I have to create the same field in production server.  The problem is this new custom field having different id. 
And I don't want to have source code just to keep track the id difference.
I'm trying to find S-Control advance api reference such as

REQUIRESCRIPT
GETRECORDIDS

Can somone point me the url?  I want to get a sense of availabe functionality provided S-Control.

Thanks in advance.

  • April 30, 2008
  • Like
  • 0
I m woking on ASP.Net 2.0 with Samples that posted on

http://wiki.apexdevnet.com/index.php/Web_Services_API#.Net_and_Visual_Basic

 

I wanted to add Web reference for my application, but I didn't able to add. When I was trying with follwoing URL's that used as an web-reference with samples(.Net and Visual Basic) that posted, I geting following error message.

 

1. https://www.salesforce.com/services/Soap/u/10.0

 
Error message  -:
 
1.1 Web Services found at this URL
 
There was an error downloading 'https://www.salesforce.com/services/Soap/u/10.0'.
The request failed with HTTP status 405: GET not supported.
 
--

405 GET not supported


Resin Professional 3.0.25 (built Wed, 05 Dec 2007 08:31:01 PST)
 
 
Error Message -:
 
2.1 Web Services found at this URL
There was an error downloading 'https://na1-api-blitz01.soma.salesforce.com/services/Soap/m/10.0'.
The remote name could not be resolved: 'na1-api-blitz01.soma.sales
 
Can any one help me in this..
 
I have tryed with localhost, I got reference as an WSDL files but I didn't get as it is and I didn't able to use all methods.
 
Thanks in advance!
 
I'm trying to query an account's contact by recordtypeid and account name. How would my soql statement look? Currently I have this but nothing is returned.
 

SELECT ID,FirstName, LastName, Primary_Contact_Title__c, Email, Phone, Fax, MailingStreet, MailingCity, MailingState, MailingPostalCode FROM Contact WHERE Account.= '" + strAccount + "' AND RecordTypeId = '" + strRecordTypeId + "'"

  • October 09, 2008
  • Like
  • 0
Hi there,
 
Following is the test class which is throwing the MIXED_DML_OPERATION error:-
 
// This class includes a test method for Trigger created on JRM_Project__c object.
Global class Automate_ProjectNumberClass {
   
    static TestMethod Void testProjectNumberAutomation()
    {
        try
        {
            //1st Step is to create a new project.
            JRM_Project__c project = new JRM_Project__c(Name = 'name');
            insert project;
           
            //2nd Step get the Region from the USER table, as this is the main criteria.
            User[] loggedUser = [Select Region__c from User where Id =:UserInfo.getUserId()];
            loggedUser[0].Region__c = 'Americas';
           
            update loggedUser[0];          
            insert project; // Once the User Region is determined simply insert the Project record
            
           
            //Updating the exisitng region which is Americas to a new region and again inserting to Project.
            // Similiar steps are repeated for each region.
           
            /*loggedUser[0].Region__c = 'Asia Pacific';
            update loggedUser[0];          
            insert project;
           
            loggedUser[0].Region__c = 'Caspian';
            update loggedUser[0];          
            insert project;*/
        }
        catch(System.DmlException e)
        {
            System.debug(e.getMessage());
        }
    }
}
///////////////////////////////////////////////////////////////////
 
Next, I found a workaround to this problem and it seems like it will work. .This feature is called - Asynchronous Apex. Therefore the same test class was edited in the following way, but the problem is when it gets executed it complains to enable this feature. However, it is a Sandbox with unlimited edition so this feature should be there. Then what could be missing???
 
Here is the code:-
 
// This class includes a test method for Trigger created on JRM_Project__c object.
Global class Automate_ProjectNumberClass {
   
    static TestMethod Void testProjectNumberAutomation()
    {
        try
        {
            //1st Step is to create a new project.
      insertProject();         
            //2nd Step get the Region from the USER table, as this is the main criteria.
             updateUserRegion('Americas');
        }
        catch(System.DmlException e)
        {
            System.debug(e.getMessage());
        }
    }
   
    static void insertProject()
    {
            JRM_Project__c project = new JRM_Project__c(Name = 'name');
            insert project; 
    }

    @future
    static void updateUserRegion(String region)
    {
            User[] loggedUser = [Select Region__c from User where Id =:UserInfo.getUserId()];
            loggedUser[0].Region__c = region;           
            update loggedUser[0];          
    }
}
////////////////////////////////////////////////////////////////////
 
Please advice.
 
Thanks
 
 
 
  • September 03, 2008
  • Like
  • 0
I wrote a S-Control to add a button that will create a new contact while passing some additional fields from the Account. The problem is that if the account name has '&' character. When I call the S-control, the Contact created  has the account name truncated. I tried to add single quote or double quote around {!Account.Name} but it did not work. Any idea?

Thanks

<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/12.0/connection.js"></script>

<script language="JavaScript">
function redirect() {

parent.frames.location.replace("/003/e?retURL=%2F{!Account.Id}&con4={!Account.Name}&00N40000001acqc={!Account.Billing_County__c}&CancelURL=%2{!Account.Id}&ent=Contact")
}
redirect();
</script>
Is there a way to obtain the ids from an sObject array?
 
For example, if I have a method that takes an sObject array as the argument, how can I obtain the ids from the sObject array?
 
public static void MyMethod(sObject[] so) {
     // how do I translate the sObject array into an array of ids from that sObject
}
 
Thanks in advance.
I had a situtation where i need to update the Multi select picklist to null.
 
I am checking the condition where if checkbox.checked = false then update muti select picklist to null and also tried passing the empty string. In Both the conditions the value is not getting updated.
 
If i pass a string value then it is getting updated.
 
Can someone plz throw an idea.
 
Thanks
  • August 05, 2008
  • Like
  • 0
Hi,
 
Is there any way to get the list fields in a record type using API or dataloader export?  I am working on a project where contact object have many different record type and I need to integrate it with another system.  and depending upon record type I need to transfer the data to another system.
 
Thanks.
 
AJ
  • August 05, 2008
  • Like
  • 0

Hi

We are getting the following message: "This lead was converted on {0}", when converting a Lead via APEX code using "ConvertLead" method.

Observation: We noticed the standard field "ConvertedDate" was null after we converted the Lead through code. When we converted the Lead by using SFDC standard Convert button, the "ConvertedDate" field is filling properly with today's date.

Did we miss anything or is there a bug in the API?

Thanks in Advance

-----------------------------------------------------------------------------------------------------

Here is the code we are using for the conversion:

            Database.LeadConvert LC = new database.LeadConvert();

            LC.setAccountId(MatchingAccounts[0].Id);
            LC.setLeadId(LeadNew[Ld].Id);             
            
            LC.setDoNotCreateOpportunity(true);
            LC.setConvertedStatus('Converted'); 
            
            Database.LeadConvertResult LCR = Database.convertLead(LC);            

 

 

Hi everyone.  

   Is there a Apex class method to get current Salesforce.com instance or URL at runtime?

I want to generate hyperlinks like https://na4.salesforce.com/{accountId} in code.  But I don't want to hard code 'na4'.

Every time I deploy the same code back to Sandbox, I must fix the instance manually.

Thanks in advance.


  • August 04, 2008
  • Like
  • 0
Hi,

  I am using query something like this

  select ActivityDateTime, Description , Subject , Location from Event where OwnerId = '" + userId + "'";

  I want to a select query that will will give me all the fields not just ActivityDateTime, Description and Subject.

  In SQL terms I mean select * from Event where ownerid = 'userid' ;

  Please let me know.

Thanks,
Sharsch


Message Edited by Sharsch on 08-04-2008 02:36 PM
Hi Everyone,
 
Do you know where I can get the enterprise web service url? I have enterprise.wsdl . I am looking that web service url link.
 
Your help is appreciated.
I'm new to Apex, and I'm trying to write a trigger that will copy several fields from a Line Item into a text field on the opportunity so I can pull them into an email template. I can get the first set to populate, but I want to be able to put several line items on the Opportunity. I've created several field on the Opp called Product1, Product2, Product3, etc.

The issue I'm having is that I'm trying to run a conditional statement that checks to see if there is already a value in the first product field, if not, put the value there, else check the next field and continue on. The problem is that when I use null the statement is always evaluating to true, and when I use '' it is always evaluating to false.

The code I'm using is below:
trigger UpdateOppProducts on OpportunityLineItem (after insert, after update) {
String TheProduct;

for (OpportunityLineItem x : trigger.new) {
Opportunity o = new Opportunity (Id = x.OpportunityId);
TheProduct = 'Coated: ';
TheProduct += x.Coated__c;
TheProduct += ', Felted: ';
TheProduct += x.Felted__c;

if (o.Product1__c == null) {
o.Product1__c = TheProduct;
} else if (o.Product2__c == null) {
o.Product2__c = TheProduct;
} else if (o.Product3__c == null) {
o.Product3__c = TheProduct;
}
//o.Product_List__c += TheProduct;
update o;
}

}


Also, eventually I would like to have this run for all Line Items that are associated with Opportunity o every time any line item is created, edited, or deleted (i'm guessing this is some sort of loop statement) so if anyone has any ideas on this it would also be very appreciated.

Thank you very much in advance to any advice anyone can give an Apex beginner!!!!
  • August 04, 2008
  • Like
  • 0

I've got an issue with a test class. I'm stuck at 56% coverage. My test method creates all the objects referenced in my controller and works fine. When I run the tests, it tells me the whole catch (QueryException ex) section of the methods is not covered. Here's a sample of what I have so far.

Code:
public static Employee__c getEmployee() {
     try {
      Employee__c employee=  [select id, kiosk__r.name, kiosk__c from Employee__c where user_name__c = :UserInfo.getUserId() Limit 1];
      return employee;
      } catch (QueryException ex) {
          ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No employee record found for current user!');
          ApexPages.addMessage(myMsg);
          return null;
     }
    }

 

Code:
public static testMethod void testDashboardControllerMethods()
      {
      //create employee      
            Employee__c employee1=new Employee__c();
            employee1.Name='Test emp 1';
            employee1.Emp_ID__c='xtyooyuoowow';
            employee1.Kiosk__c=kiosk.Id;
            employee1.Quota_Status__c='Active';
            employee1.Sys_ID__c='127uijo90';
            employee1.User_Name__c=[Select Id from user where Isactive=true Limit 1].Id;
            employee1.Weekly_Hours__c=20;
            insert employee1;
            dashboardController.getEmployee();
       }

I tried creating a QueryException in the test method by adding a second test method that creates a employee record but not specifying user_name__c.

Code:
public static testMethod void testDashboardControllerMethods2() {
            //test the exception errors
            Employee__c employee1=new Employee__c();
            insert employee1;
            dashboardController.getEmployee();
      }

That doesn't seem to work. Any suggestions?

Is it possible to replace the user interface for the Customer Portal with Visual Force pages?  If so where do you set it?
We are trying to do a trigger to calculate the amount in USD and store in a custom field in Opportunity. But I am facing the NullPointerException

Code:
trigger opptyAmountNusd on Opportunity (after update) {
//Calculates the USD equivalent and updates in another field

if (Trigger.isUpdate) {
    //for (Opportunity o_oppty : Trigger.old) {
   
    Opportunity[] opps = new List<Opportunity>();
        for (Opportunity n_oppty : Trigger.new) {
            Opportunity opp_tmp = n_oppty;
           
            if ((n_oppty.Amount != 0) ||(n_oppty.Amount != NULL) ) {
                    Decimal a = n_oppty.Amount;
                    String c = n_oppty.CurrencyIsoCode.substring(0,3);
                   
                    CurrencyType ct = [Select ConversionRate from CurrencyType where IsoCode=:c limit 1][0];
           
                    Decimal cr = ct.ConversionRate;
                   
                    opp_tmp.Amount_In_USD__c = cr*a;
                    opps.add(opp_tmp);
                   
                    //n_oppty.Amount_In_USD__c = cr*a;      
            }
        }
    //}
   
     for (Opportunity opp_tmp : opps) {
    
         update opp_tmp;
     }
}



}

Message Edited by rob_ocp on 07-10-2008 11:08 AM

Message Edited by rob_ocp on 07-10-2008 11:11 AM
I have to following code snippet

Code:
<apex:column ... >
{!IF(ISNULL(var.Name), "&nbsp;", var.Name)}
</apex:column>


This block does not generate &nbsp; as expected.  Instead, it renders &#160; instead. 

Does anyone know the proper coding to render &nbsp;? 


Thanks in advance.
when creating a case through the api in the below sample code, the case is created without error and all specified fields populate except Reproduced__c, which is a custom field of boolean type. when debugging, m_Reproduced is boolean and contains valid data. and i have tried values of both True and 1. yet neither value seems to have an effect- the field simply will not set via api, but i can set it through the salesforce web interface if i edit the case.

i also tried to manually set other, non-custom fields like IsClosed on create and those values did not take either.

any insight is greatly appreciated.


                Dim oCase As New sforce.Case()
                With oCase
                    .ContactId = m_ContactID
                    .Type = m_CaseType
                    .CreatedDate = Date.Now
                    .Description = m_CaseDescription
                    .Product__c = m_Product
                    .Steps_to_Reproduce__c = m_StepsToReproduce
                    .STT_Version_Number__c = m_VersionNumber
                    .Subject = m_Subject
                    .Component__c = m_Component
                    .Reproduced__c = m_Reproduced
                End With

                Dim oSaveResult() As sforce.SaveResult
                oSaveResult = oProxy.create(New sObject() {oCase})
Hi I am having some issue passing a long query string over to a third services provider from salesforce.
Due to the limitation of query string size, sometimes it fail to create a connection.
Does anyone out there have a way to solve this issue?
Apex code? Encoding value?
 
thanks