• arunk
  • NEWBIE
  • 200 Points
  • Member since 2009

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 35
    Replies

So I'm kind of new to using Apex and lately I've been trying to build a trigger to replicate the default functionality of the NPSP that automatically creates an organization for a contact that is not associated with an organization at creation for a custom object I have called staff member. I'm trying to work with the developer book provided by SalesForce but I'm having trouble finding useful examples so I've started looking for code bits I think might work and using trial and error methods to test them. So far no luck. I was hoping someone here could point me in the right direction as I have no idea if what I'm trying is close or if I'm way off. 

 

Basically, I have three objects: a staff member, an organization, and an affiliation. Using an Apex trigger I want to be able to create an organization object and an affiliation object after an insert to staff member. The organization object will hold information from the staff member object and the affiliation object will link the staff member and organization objects with their IDs.  

 

Here's the code I have right now:

 

 

trigger CreateNewOrg on Staff_Member__c (after insert) { List<Organization__c> newOrgs = new List<Organization__c>(); // build list in memory List<Affiliation__c> newAffs = new List<Affiliation__c>(); for (Staff_Member__c member : Trigger.new) { Organization__c newOrg = new Organization__c(); newOrg.Organization_Name__c = member.Last_Name__c; newOrgs.add(neworg); Affiliation__c newAff = new Affiliation__c(); newAff.Staff_Member__c = member.ID; newAff.Organization__c = newOrg.ID; newAffs.add(newAff); } Database.SaveResult[] orgs = Database.insert(newOrgs, false); Database.SaveResult[] affs = Database.insert(newAffs, false);}

 

Just to explain how I think this code should be working, it starts off by creating two lists, one of type object and the other of type affiliation. Then for each staff member, create a new organization, set the organization name to the value of the staff member's last name and then add it to the list of organizations. Then create a new affiliation object, set the staff member field to the current staff member's ID and the organization field to the organization's ID, then add the affiliation to the list of affiliations. After going through all the new staff members, write the new lists of organization and affiliation objects to the database.  

 

I really appreciate any help and advice anyone can give me on this topic. 

 

 

I am trying to do a nested SOQL statement. I want to have a query that I order by descending to find the biggest number and then use that number to only find the records with that number. So one part of the nested query will find the largest number and then I will use that number to show only the records that have number.

 

 

I can find the value with this query

 

 

Select Height__c 

from Person__c

Order By Height__c desc limit 1 

 

Just wondering if i can get this value to compare the rest of the records and display the results thanks. 

 

Thanks  

Message Edited by intern2424 on 11-02-2009 07:36 AM

Hi everybody,

 

I just set up my Eclipse ( 3.3.2) and installed Force.com IDE (16.0). When I try to get create a new Force.com  project , I got the "Unable to fetch organization details for..."  message. It says Eclipse is not able to tunnel through proxy and proxy returns "http/1.1 407 Proxy authentication required ..."

 

 

 

my eclipse.ini  file reads like : 

--launcher.XXMaxPermSize 256M

-vmargs -Dorg.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

-Dosgi.requiredJavaVersion=1.5

-Xms40m

-Xmx256m    

 

 

I would appreciate if you could share your prior experiences.

 

Thanks in advance

 

Mehmet 

  • October 15, 2009
  • Like
  • 0

on Case Object i have a custom field case_assigned_to__c (LOOKUP) to user.

 

  FieldName is Case_Assigned_to

  API Name  is Case_Assigned_to__c

 Child Relationship Name is AssignedTo

 

When i query

 

 

(Select Id,Contact.Name,Subject,ClosedDate,Owner.Name,Case_Assigned_to__c.Name from case limit 10)

I am receving this error Didn't understand relationship 'Case_Assigned_to__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

 
I also tried AssignedTo__r.Name

 

Please advise....How to grab the user name ?

 

 

 

 

Any search engine-friendly way to move an existing website to force.com, I mean to handle the change of urls?

 

from 

www.domain.com/abcdefg.asp

to

www.domain.com/abcdefg 

  

 

Thanks 

Hi,

 

I've been trying to extend Sobject class in flex actionscript 3 code, but so far no success.

 

I have my custom object for example MyObject__c and I would like to have a class MyObjectVo extends Sobject

in flex so I can have strongly typed object for faster development in my code instead of having to have hard coding the properties.

 

Any ideas, a code sample will be exteremly helpful.

 

Here is what I've got:

 

 package com.seventicks.timesheet.model.vo
{
    public class TimesheetVo
    {
        public var type:String = "Timesheet__c";
        public var Activity__c:String;   
        public var ActivityType__c:String;
        
        public function TimesheetVo()
        {

        }    
    }
}

  • August 21, 2009
  • Like
  • 0

Hi,

 

I have created Flex grid, on while I want to populate Account sObject's data.

 

Code of mxml file, After successful build, I have uploaded .swf file into static resource.

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:salesforce="http://www.salesforce.com/" creationComplete="login(event)"> <salesforce:Connection id="apex" serverUrl="https://www.salesforce.com/services/Soap/u/9.0" /> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import com.salesforce.results.QueryResult; import mx.utils.ObjectUtil; import mx.controls.Alert; import com.salesforce.AsyncResponder; import com.salesforce.objects.LoginRequest; private function login(event:Event):void { var lr:LoginRequest = new LoginRequest(); // lr.server_url = parameters.surl; // lr.session_id = parameters.sid; Alert.show(parameters.session_id); Alert.show(parameters.server_url);

// session_id and serverurl is giving authentication error in Firefox, IE, Safari

lr.session_id = parameters.session_id; lr.server_url = parameters.server_url;

 // username and password is working fine only in Firefox, and IE, Safari gives connection error

/* lr.username = "SFDC_username" lr.password = "SFDC_password"; */

 

lr.callback = new AsyncResponder(loadData, handleFault); apex.login(lr); } [Bindable] private var accountList:ArrayCollection = new ArrayCollection(); private function handleFault(fault:Object):void { Alert.show(ObjectUtil.toString(fault)); } private function loadData(lr:Object):void { apex.query("Select Name, Phone, Type From Account", new AsyncResponder( function(qr:QueryResult):void { if (qr.size > 0) { accountList = qr.records; } }, handleFault) ); } ]]> </mx:Script> <mx:DataGrid dataProvider="{accountList}" left="10" right="10" top="10" bottom="10"> <mx:columns> <mx:DataGridColumn dataField="Name"/> <mx:DataGridColumn dataField="Phone"/> <mx:DataGridColumn dataField="Type"/> </mx:columns> </mx:DataGrid> </mx:Application>

 

Visualforce page code (SimpleFlexGrid.page):

<apex:page > <!-- Begin Default Content REMOVE THIS --> <h1>Congratulations</h1> This is your new Page: SimpleFlexGrid <!-- End Default Content REMOVE THIS --> <apex:flash id="flexSOs" src="{!$Resource.SimpleFlexGrid}" height="100%" width="100%" flashvars="session_id={!$Api.Session_ID}&server_url={!$Api.Partner_Server_URL_90}"/> </apex:page>

 

While loading  /apex/SimpleFlexGrid page, I am  following error;

 

(com.salesforce.results::Fault)#0
  context = (null)
  detail = (Object)#1
    fault = (Object)#2
      exceptionCode = "INVALID_SESSION_ID"
      exceptionMessage = "Invalid Session ID found in SessionHeader: Illegal Session"
      xsi:type = "sf:UnexpectedErrorFault"
  faultcode = "sf:INVALID_SESSION_ID"
  faultstring = "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session"

 

 

Flashvars in apex:flash tag gives above error in all browser.

 

But if I remove flashvars, and hardcode username, and password in actionScript, everything is working fine except in safari browser.

 

Any help on flashvars session_id, server_url would be appreciated.

 

Thanks,

Ankur

 

I have custom object that looks like this in ActionScript. There is a corresponding custom object in SalesForce called LineItem.

 

 

public class LineItem { private var sfId:String; private var impressions:int; private var cpm:Number = 0.0; private var product:String; private var cost:Number; private var selected:Boolean; private var allocation:Number = 0.0; }

 

 What is an clean/elegant way of serializing this object from ActionScript to XML and then sending it to SalesForce.

 

Do I inherit from SObject and override the toXML() method? I looked at examples of developer.salesforce.com but none of them do anything like this.

 

Hi all,

 

Suppose there are three users in my salesforce account: U1, U2 and U3. Also suppose U2 and U3 have shared there calendar with U1.

Now if i am using Outlook connect with U1's credentials, is there some way to see (and edit) U1 and U2's calendars through outlook??

Any possibility for something like this ?

 

Suppose I have a person responsible for scheduling activities for entire team...

How can I impliment it in salesforce? 

 

Pls comment..

 

Thnaks,

Arun.

  • July 02, 2009
  • Like
  • 0

Hi,

 

I am new to salesforce. And am planning to create a hotel management system.

Suppose there are four types of roles: Client, waiters, chefs and managers.

What i want is that whenever a client pays a bill amount greater then a predefines value, a alert should pop-up in front of all logged-in managers. Is this possible? Are there any work arounds for this ?

 

 

I know that email alerts are possible in this scenario. But i would prefer a pop-up alert. 

 

Thanks in advance,

arun. 

Message Edited by arunk on 06-09-2009 05:17 AM
  • June 09, 2009
  • Like
  • 0

Hi everybody!

 

I have a big giant questionnaire, and during my save process in my controller, I want to do some error-checking.  I want to make sure fields aren't more than the 255 characters that they should be.  Here's my "code" that I've gotten to work so far:

 

public PageReference save() { string TestLength = 'ThisShouldBeTheFieldFromTheVisualForcePage'; Integer LengthOfField = TestLength.length(); if (LengthOfField>255) {pop up a window saying that it's too big and break out of page} else {save the questionnaire} }

 

This code works fine, but when I try to replace the value 'ThisShouldBeTheFieldFromTheVisualForcePage' with the actual field, as seen in this code:

 

 

string TestLength = qGeneral.Project_Name__c;

it doesn't seem to work.  It errors out on the "Integer LengthOfField = TestLength.length();" line.  And Eclipse gives an error that says "An unexpected error has occured", which doesn't help me at all.  I tried defining the variable beforehand...I tried checking for "null" before this line thinking that it might not like that.  I just can't get it to work, and I'm sure it's something dumb, but I've been beating myself against the wall for awhile now, and I figure I'd come here and listen to someone tell me how stupid I've been to save some time.

 

Any and all help is extremely appreciated.

 

Thanks!

 

-Jason

Message Edited by JasonGardner on 11-03-2009 07:46 PM


I am creating a public Web form in Visual Force for the Force.com site. The user is not logged in. When he fill the form and click the submit button,  the form will create the a contact and Account records (under Contact and Account Standard object), and create a case for that contact(under case standard object).

 

I am able to create the contact but not able to create and  insert the case for that contact.

 

The controller code I  am using is listed below:

 

public class TechnicalServiceController {
   
    public String companyName{set; get;}
    public String firstName{set; get;}
    public String lastName{set; get;}
    public String title{set; get;}
    public String phoneNumber{set; get;}
    public String emailId{set; get;}
    public String department{set; get;}
    public String firstAddress{set; get;}
    public String secondAddress{set; get;}
    public String cityOrTown{set; get;}
    public String state{set; get;}
    public String postalCode{set; get;}
    public String country{set; get;}
    public String typeOfRequest{set; get;}

 

 public PageReference saveRecords() {
           
       try
       {
       Contact contactToStore = new Contact();
           contactToStore.FirstName = firstName;
           contactToStore.LastName = lastName;
           contactToStore.Phone = phoneNumber;
           contactToStore.Email = emailId;
           contactToStore.MailingCountry = String.valueOf(country);
           insert contactToStore;
  

//new Object of type Account Standard Object    

 Account accountToCreate = new Account();
           accountToCreate.Name = companyName;
           insert accountToCreate;
            
           
      //new Object of type Case Standard Object
      Case caseToCreate = new Case();                     //don't know how to go onward from here. getting error here
            caseToCreate.Contact = contactToStore.lastName;    

            caseToCreate.Account = companyName;       
           return null;        
        }
        catch(Exception e)
            {
            ApexPages.addMessages(e);
            return null;
            } 

 

For the code block ab ove:

 

Contact and Account are Lookupfields on Case record  but in my controller/webpage these are text fields and I am trying to store these text fields in the above 2 lookup fields

when I try to store them in the corrresponding fields on the case, it gives me following error message:
Error: Illegal assignment from String to SOBJECT

Is there anyone who can help me on it. I am not using Web to case because in that case I have to display
the fields from my case object on the web page which is not required as some fields are picklist on my webpage and they
are stored as text on case object record.

 

Also I need to insert the Contact and Case Related List on the Account Record; And Cased Related list in the Contact record for the corresponding Account, Contact , and Case  I create.

 

 

Is there anyone who can please help me on this...!!!!

We have a requirement to create a custom field on the Opportunity object with a lookup to Contacts to store the BU Business Development contact (we have a requirement to make this a mandatory field).  We have created a field BU_Business_Development__c (we actually have a need for 4 other fields but I will come to that later). The business would like to create a Contact Role for the contact selected in the BU Business Development field linking back to the opportunity. I have created a trigger that successfully populates the OpportunityContactRole (and manages deletions & updates from the BU Business Development field. 

trigger Opportunity_NewBUBD on Opportunity (after insert, after update) { for (Opportunity o : Trigger.new) { if (trigger.isUpdate) { for (Integer i = 0; i < Trigger.old.size(); i++) { if (trigger.Old[i].BU_Business_Development__c != Null) { if (trigger.Old[i].BU_Business_Development__c != o.BU_Business_Development__c) { OpportunityContactRole [] oDWs = [select id from OpportunityContactRole where OpportunityId = :trigger.old[i].id and ContactId=:trigger.old[i].BU_Business_Development__c and Role = 'BU Business Development']; delete oDWs; } } Integer oDWs1 = [select count() from OpportunityContactRole where OpportunityId = :trigger.old[i].id and ContactId =:trigger.new[i].BU_Business_Development__c and Role = 'BU Business Development']; if (oDWs1 == 0 & o.BU_Business_Development__c != Null) { OpportunityContactRole OCR1 = new OpportunityContactRole (OpportunityId=o.id, ContactId =o.BU_Business_Development__c, Role = 'BU Business Development'); insert OCR1; } } } if (trigger.isInsert) { if (o.BU_Business_Development__c != Null) { OpportunityContactRole OCR1 = new OpportunityContactRole (OpportunityId=o.id, ContactId = o.BU_Business_Development__c, Role = 'BU Business Development'); insert OCR1; } } } }

 

 
  1. I would be very grateful on your views of the design of the apexcode?
  2. I believe that some of this code should be called using a function to facility the reuse of the code; can you provide some suggestions on this? (i.e. rows 26-30 and 38-42)
  3.  I would like to use dynamic code utilising an array of fields that should be ‘monitored’ so that one piece of code can be used to populate the OpportunityContactRole for many fields.  (This would need to have a variable for the Role and the fieldname.) Any ideas?
Thanks in advance Jason
  • November 03, 2009
  • Like
  • 0

I have a VisualForce page with many different rendering options based on different vars being set.  One of the pages (if step=2) will display a Lead object.  But on that page if the user clicks any of the buttons, the Return URL is set to the generic name of the VisualForce page.  Is there any easy way to override the Return URL for all buttons on the page?  I've seen examples where you can override a single button's retURL but I'm looking for a more global option.

I'm working with tabbed interfacing and having some difficulty with a feature I would like to implement.  After selecting a tab within an instance of an object, I would like to be able to display the fields related to the object represented by the tab.  For example, if I have a student object with a "classes" tab, I would like to display the current classes the student is taking (and just links to the other instances of the classes object).  Is there any way to implement this feature in SalesForce, using Apex or any other method?

 

Thanks in advance

Can someone point me in the right direction for writing a trigger that updates a field on the Account Record if a contract is expired?  

 

For instance if a contract is current (start and end date are within current date) it would update the field to say current.  If the contract end date is a date in the past and there are no other current contracts it would update the field to "lapsed"

 

Thanks in advance 

  • November 03, 2009
  • Like
  • 0

So I'm kind of new to using Apex and lately I've been trying to build a trigger to replicate the default functionality of the NPSP that automatically creates an organization for a contact that is not associated with an organization at creation for a custom object I have called staff member. I'm trying to work with the developer book provided by SalesForce but I'm having trouble finding useful examples so I've started looking for code bits I think might work and using trial and error methods to test them. So far no luck. I was hoping someone here could point me in the right direction as I have no idea if what I'm trying is close or if I'm way off. 

 

Basically, I have three objects: a staff member, an organization, and an affiliation. Using an Apex trigger I want to be able to create an organization object and an affiliation object after an insert to staff member. The organization object will hold information from the staff member object and the affiliation object will link the staff member and organization objects with their IDs.  

 

Here's the code I have right now:

 

 

trigger CreateNewOrg on Staff_Member__c (after insert) { List<Organization__c> newOrgs = new List<Organization__c>(); // build list in memory List<Affiliation__c> newAffs = new List<Affiliation__c>(); for (Staff_Member__c member : Trigger.new) { Organization__c newOrg = new Organization__c(); newOrg.Organization_Name__c = member.Last_Name__c; newOrgs.add(neworg); Affiliation__c newAff = new Affiliation__c(); newAff.Staff_Member__c = member.ID; newAff.Organization__c = newOrg.ID; newAffs.add(newAff); } Database.SaveResult[] orgs = Database.insert(newOrgs, false); Database.SaveResult[] affs = Database.insert(newAffs, false);}

 

Just to explain how I think this code should be working, it starts off by creating two lists, one of type object and the other of type affiliation. Then for each staff member, create a new organization, set the organization name to the value of the staff member's last name and then add it to the list of organizations. Then create a new affiliation object, set the staff member field to the current staff member's ID and the organization field to the organization's ID, then add the affiliation to the list of affiliations. After going through all the new staff members, write the new lists of organization and affiliation objects to the database.  

 

I really appreciate any help and advice anyone can give me on this topic. 

 

 

I am trying to do a nested SOQL statement. I want to have a query that I order by descending to find the biggest number and then use that number to only find the records with that number. So one part of the nested query will find the largest number and then I will use that number to show only the records that have number.

 

 

I can find the value with this query

 

 

Select Height__c 

from Person__c

Order By Height__c desc limit 1 

 

Just wondering if i can get this value to compare the rest of the records and display the results thanks. 

 

Thanks  

Message Edited by intern2424 on 11-02-2009 07:36 AM

I have to compare Date fileld of a particular object with another Date field.

 

Like Start_date__c >= End_Date__c ( will it work in Apex? if not then waht is the syntax)

Hi, I was wondering if anyone can help me out with something. I was wondering if You can create a object like "Contacts" and add other fields like phone number, age, address street, zip all from eclipse ide. 

 

Then I was wondering if I can get the max age, min age, average age and number of contacts.

 

Thanks  

Hi,

 

I'm developing a sample application in flex. I'm trying to store the records from flex to salesforce.com, can anyone tell how to do this in flex.

 

I had tried this code to insert records from flex but its not working.Is anything wrong in my code pls check it and reply.

 

 

private function sampleinsert(lr:Object):void { force.query("SELECT Id,Department FROM Contact " + "WHERE Contact.Email='bond_john@grandhotels.com'" , new AsyncResponder(function(result:QueryResult):void { opps = result.records; })); var temp:String; //opps.Department="Medicare"; var newItems:Array= new Array(); newItem=new SObject("Contact"); //Alert.show(opps.getItemAt(0,0).Id.toString()); newItem.Id=opps.getItemAt(0,0).Id; //newItem.Name=textinput.text; //temp=opps.getItemAt(0,1).Department; newItem.Department="ssssss"; Alert.show(newItem.Department.tostring()); newItems.push(newItem); force.upsert("Id",[newItems], new AsyncResponder( function ():void{ Alert.show("ok seems like authors are saved"); } )); }

 

Thank You.
Message Edited by Coder on 10-22-2009 11:28 PM
  • October 23, 2009
  • Like
  • 0

 

I am trying to take the date & time from a date & time field and copy to another date & time field on a Case.

Basically, Field A is populated by a date/time. I want to copy that date/time from Field A into Field B so I have it in 2 fields.

I'm sure it is something simple, but I cannot figure it out.

 

Thanks!

 

Somehow my development environment has gotten into a bad state.  I am working on a VF page and a custom controller (using Eclipse).  Whenever I try to save my controller I get the following message:

 

 
Save error: Conflict found while preparing to save 'controller.cls' to server.  Remote instance has been updated since last save or sync.  Use the Synchronize Perspective to resolve the conflict.   

 

I am also getting save errors when trying to save the VF page in Salesforce.  

 

I have tried deleting all the VF pages and the controller class that is on the server and resaving everything again, but after a few saves, I start to get the errors again. 

 

I cannot find the Synchronize Perspective function in Eclipse that the error message refers to.

 

Any ideas?  Maybe a time drift issue between my laptop and SF server?

If I am using the partner WSDL (if it matters), for a single SOQL query via the WS API, what is the maximum number of records I can query if I use query + multiple querymore calls?

 

Is it 10000 records?

 

 

 

Can someone help me on this?  We need to have multiple 'owners' of a record for reporting so we added 4 additional fields but we want to make sure if that person is already entered into one of the fields they can't be entered again.  This works except that the fields are blank...which my formula assumes they're equal.  Here's my formula:

 

OR( OwnerId == Owner_2__c, OwnerId == Owner_3__c, OwnerId == Owner_4__c, OwnerId == Owner_5__c, Owner_2__c==Owner_3__c, Owner_2__c==Owner_4__c, Owner_2__c==Owner_5__c, Owner_3__c==Owner_4__c, Owner_3__c==Owner_5__c, Owner_4__c==Owner_5__c )

 

 

 

on Case Object i have a custom field case_assigned_to__c (LOOKUP) to user.

 

  FieldName is Case_Assigned_to

  API Name  is Case_Assigned_to__c

 Child Relationship Name is AssignedTo

 

When i query

 

 

(Select Id,Contact.Name,Subject,ClosedDate,Owner.Name,Case_Assigned_to__c.Name from case limit 10)

I am receving this error Didn't understand relationship 'Case_Assigned_to__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

 
I also tried AssignedTo__r.Name

 

Please advise....How to grab the user name ?

 

 

 

 

Hi,

 

Is there a way to get the actual object using the object name?

 

Thanks.

  • October 02, 2009
  • Like
  • 0

I've got to course-correct on an implementation I'm looking to build.  I've got an embedded SWF in our SF instance that uses the Google Maps API for Flex and is a positive feedback loop into Location data that's stored in SF.  It works really well and is pretty quick.  The Product Management team is excited about adding Google Earth KML overlays to this map.  The Google Maps API for Flex doesn't have great support for parsing KML but they're getting there slowly.  I've looked at a couple of different interfaces for the KML/KMZ file and Google Earth sharing.   One approach I took that is not working so well is to load the KML at time of loading of the SWF.  I've hosted the KML out on Box.net.  I'm a paying Box.net customer so the download begins immediately when attempting to load the file using the URLLoader class.  The download takes a long time, though, and is causing URLLoader to time out (the default setting is 15 seconds and even at home with High-speed internet connection this is taking longer than 15 seconds).

 

Is there a way to access Salesforce static resources in a Flex swf?  I would guess that I would still use URLLoader but maybe use the $ syntax for Static Resources?  By doing this I could offload the burden of downloading the file from a public internet location and presumably speed things up.  It doesn't make sense for me to incur a hit downloading the file each time a location is accessed.

 

I spent some time on the webinar last week trying to understand what new features would be available in Summer '09.  One that piqued my interest was Batch Apex.  Ideally, I'd like to blend with the feature above and update the static resource with realtime data on a scheduled (or ad hoc if necessary) basis