• Marty Y. Chang
  • NEWBIE
  • 55 Points
  • Member since 2010

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 41
    Replies
I'm getting the following error when attempting to convert a Lead:

System.DmlException: ConvertLead failed. First exception on row 0; first error:
INVALID_STATUS, invalid convertedStatus: Closed - Converted: []

I have determined that this is happening because I have more than one converted LeadStatus.  Different Lead RecordTypes have corresponding Lead Processes associated to them, each one using a different converted LeadStatus.

The code I have to pick LeadStatus is:

LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus  where IsConverted=true limit 1];

Obviously, this just picks the first available converted LeadStatus, which for some RecordTypes is not the appropriate one.

Could someone please point me to a code sample that does a smarter
LeadStatus selection?

 

Also, I'd like to understand why convertLead started failing with this error in the last month or so, since everything else stayed the same.  Someone suggested in the forum that there were several issues after the Spring 12 release.
Thanks!
  • April 07, 2012
  • Like
  • 0

Does anyone know how to get a Set<String> of all hashtags used in a Chatter post or comment?

I'm trying to setup a Salesforce Site that will enable a user to create new Customer Portal user accounts and to login using those accounts.  My question is:  During registration and login, how can I ensure that passwords are not sent across the Internet in plain text?

When I perform a certain export operation using the Apex Data Loader GUI, the operation takes about 10 seconds to complete.

 

When I attempt the exact same operation using the Apex Data Loader through the command line, the operation takes almost 1 hour to complete.

 

Has anyone else encountered this massive discrepancy?  And does anyone have any ideas on how to speed up the command line operation?

Is it possible to make Campaign Member Status a field on a Web-to-Lead form?

 

For example, with an RSVP Web-to-Lead form we want to present the options "Yes", "Maybe" or "No.  These correlate to different Campaign Member Statuses for the Campaign.

Does anyone have any thoughts or guiding philosophies on when to extend a controller and when to create a controller extension?

 

One example that I'm working on right now:

 

  • I have a customer portal for which I am creating a Visualforce tab to enable the customer to update his/her own contact record.
  • I have created a custom controller called CustomerPortalUserCtrl that uses SOQL to grab AccountId and ContactId for the current user.

 

 

My question:  For the Visualforce tab to edit the contact record, should I extend CustomerPortalUserCtrl or write an extension for it?

 

 

public class CustomerPortalUserContactCtrl
        extends CustomerPortalUserCtrl {
    public Contact contact { get; set; }
    
    private Boolean editing;
    public Boolean getIsEditing() {
        return editing;
    }
    
    public CustomerPortalUserContactCtrl() {
        super();
        
        List<Contact> contacts =
                [SELECT Id, FirstName, LastName,
                        HomePhone,
                        OtherPhone
                 FROM Contact WHERE Id = :user.ContactId];
        
        if (contacts.size() > 0) {
            contact = contacts.get(0);
        }
    }   // public CustomerPortalUserContactCtrl()
}

 

public class CustomerPortalUserContactExt {
    public Contact contact { get; set; }
    
    private Boolean editing;
    public Boolean getIsEditing() {
        return editing;
    }
    
    public CustomerPortalUserContactExt(CustomerPortalUserCtrl ctrl) {
        List<Contact> contacts =
                [SELECT Id, FirstName, LastName,
                        HomePhone,
                        OtherPhone
                 FROM Contact WHERE Id = :ctrl.user.Id];
        
        if (contacts.size() > 0) {
            contact = contacts.get(0);
        }
    }   // public CustomerPortalUserContactExt(CustomerPortalUserCtrl)
}

 

One of my thoughts is this:  Extend the controller if I need to access the controller members in my new page; Create a controller extension if the only reason I need the controller is to initialize some internal variables for the new page.

 

 

Note:  My goals are complicated by the fact that we deal with Person Accounts, so using an apex:detail component would not work.  An apex:detail component with subject="{!$User.ContactId}" would render an Account detail page, which is not editable.

Does anyone have any ideas on why I’m getting this error when trying to execute Apex via Javascript in a custom button?

 

{faultcode:'soapenv:Client', faultstring:'The content of elements must consist of well-formed character data or markup.', }

 

I’m trying to following the example in the documentation below:

 

“Apex in AJAX”

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_and_ajax.htm?SearchType=Stem

 

My Apex class method is essentially as follows:

 

global class MyInterface {
  webService static void performInterfaceAction(List<Id> accountIds) { }
}

 

My JS in the button is as follows:

 

{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/21.0/apex.js")}

var result = sforce.apex.execute("MyInterface", "performInterfaceAction", {!GETRECORDIDS( $ObjectType.Account )});

alert(result);

location.reload(true);

 

Hi All,

 

We can login to salesforce from any OS like Windows, IMac, Android, etc.

I need to do some specific task based on the logged in user's OS.

 

Can any one please help me with this.

 

Thanks.

Hello,

 

I need assistance in the creation of a trigger that will not allow the deletion of an Opportunity under the following circumstances:

 

  • If there is an Agreement Name (Name) (echosign_dev1__SIGN_Agreement__c is object)
  • Or if there is a Sales Order No (Name) (Sales_Order__c is object)
  • Or if there is an Sales Invoice No (Name) (Sales_Invoice__c is the object)
  • Or if there is an attachment present in the Agreement

 

Thank you for your help.

 

Regards,

Alex

Hi,

 

We have exposed enterprise wsdl to one of the consumer where they need to send the attchments as well as part of webservice calls .

 

1. Does Enterprise wsdl supports attachments

 

2. Can we also retrieve the attachments from custom object through webservice

 

I am also looking for some documentation on these points which I can share with consumer

 

Thanks

I have searched high and low and cannot find anything on how to loop throught this subquery. The inner FOR loop will not compile.  The new console doesn't tell me what the issue is -- it just shows a red exclamation mark.

 

What I really need to do is search through all opportunties that have a specifiic condition and go get the related contact email and name where the contact is flagged as Email Broker (check box field).  If I could get those results I believe I can use it to build email arrays and send the array off to the email class.

 

Any help is appreciated.

 

 

for ( Contact c : [ SELECT Id, Email, Name, (SELECT OpportunityId
                                                     FROM OpportunityContactRoles ) 
                                   FROM Contact 
                        WHERE Email_Broker_Reminder__c = true ] ) {
                            for ( OpportunityContactRoles detail : c.OpportunityContactRoles ) {
                                
                            }
                            
            //contactsMap.put(c.id, c);
                            
        }    

 

I'm getting the following error when attempting to convert a Lead:

System.DmlException: ConvertLead failed. First exception on row 0; first error:
INVALID_STATUS, invalid convertedStatus: Closed - Converted: []

I have determined that this is happening because I have more than one converted LeadStatus.  Different Lead RecordTypes have corresponding Lead Processes associated to them, each one using a different converted LeadStatus.

The code I have to pick LeadStatus is:

LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus  where IsConverted=true limit 1];

Obviously, this just picks the first available converted LeadStatus, which for some RecordTypes is not the appropriate one.

Could someone please point me to a code sample that does a smarter
LeadStatus selection?

 

Also, I'd like to understand why convertLead started failing with this error in the last month or so, since everything else stayed the same.  Someone suggested in the forum that there were several issues after the Spring 12 release.
Thanks!
  • April 07, 2012
  • Like
  • 0

I've run into an odd scenario involving a cross-object validation that I'd like some fresh eyes on.  I want to prevent a Case from being created, updated or closed if the Case.Type is not in agreement with the associated Account's recordtype.

 

It sounds like a straightforward use case for a Validation Rule, but insert()s slip on through anyway (perhaps because Account.recordtypeId isn't available until after the Case is first saved..?  Guessing here.)  Updates and Case close are prevented, but that's not enough.

 

So I created a Case trigger (before insert, before update) that checks for Case.Type, creates a Set<Id> of Account Ids for the types I want to validate, retrieves the Account.Ids for the Account recordtypes I care about, and then uses addError() to flag those Cases that violate the rule.

 

i.e. Accounts of recordType 'X' must have Cases of Case.Type "Xtype", or I apply addError('Please use Case type "Xtype" when blah, blah blah');

 

The trigger works great, but is proving difficult to test:

 

#askForce pointed to a great example of Unit Testing for (presumably) an addError() use Testing Example

 

I create a Case with an invalid type, then attempt an insert() or update() using a try/catch block, then use the example to look at the exception - but no exception is thrown.

 

UI works great, though.

if (c.AccountId == a.Id && c.Type <> 'Xtype') {
	c.addError(' You must select a Case type of \'Critical Care\', as this is a Critical Care account.');
}

 

Hello averyone,

I am new to APEX, VF and all. So thanks for your help. What you will find below is very simple but how come the setRedirect() does not work for the view() method? Thanks again.

 

THE PAGE

<apex:page sidebar="false" showheader="false" standardController="Contact" extensions="CCNPositionContExt">
<apex:form >
<apex:commandButton action="{!view}" value="View"  />
<apex:commandButton action="{!cancel}" value="Cancel" />
</apex:form>
</apex:page>

THE CONTROLLER

public with sharing class CCNPositionContExt {
public CCNPositionContExt(ApexPages.StandardController sc) {
  }
public PageReference view(){
  Contact myContact;
  myContact = [SELECT Id FROM Contact WHERE Email =:  'chloe@porsche.com' ];
  PageReference viewPage = new ApexPages.StandardController(myContact).view();
  viewPage.setRedirect(true);
  return viewPage;
}
public PageReference cancel(){
PageReference cancel = page.CCNAbandon;
return cancel;
}  
}

I want to send an email to the owner  when someone attach a file to opp, so here is my trigger it works fine i just use plain text body and html body but i want to insert template so i created template and used that id by trigger doesn't shows up any error but when i try to attach file to opp record it throws me error saying Invalid Id: john@company.com, here is my trigger

 


Trigger AttachmentEmail on Attachment (after insert) {
 set<Id> aId = new set<id>();
 for(Attachment a:trigger.new){
   aId.add(a.Id);    
 }
 
 list<Attachment>alist=[select Id, Name, ParentId, OwnerId from Attachment  where Id in: aId];
 String parentObj = alist[0].parentId;
 if(parentObj.startsWith('006')){
 
     list<User> ulist = [select Id, email from User where Id =:alist[0].OwnerId];
     String emailId = ulist[0].email;
     Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                        //String[] toAddresses = new String[] {emailId};
                        mail.setTargetObjectId(emailid);
                        mail.setTemplateId('00XQ0000000MIJJ');
                        //mail.setToAddresses(toAddresses);             
                       // mail.setSubject('A new file is attached to your request' );
                       // mail.setBccSender(false);
                       // mail.setUseSignature(false);
                        //mail.setPlainTextBody('Please click on the link below to view your file');
                        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
            }

}

 

 

Hi,

 

Our org uses Person Accounts.

 

This trigger I wrote works perfectly when creating a Person Account. However it throws the following error when creating a normal business Account - 

 

System.QueryException: List has no rows for assignment to SObject: Trigger.CreateCase: line 14, column 1

 

Here is the trigger - 

 

//define trigger and when it fires
trigger CreateCase on Account (after insert) {


  //create list of cases to be inserted
  List<Case> newcase = new List<Case>();


  //find the ID of the correct record type
  Id rtId = [select Id, name from RecordType where name ='My Case Record Type' and SObjectType='Case' limit 1].Id;
  
  //find contact ID to attach to the to case
  Id personContact = [select id, Name from Contact where Contact.AccountId in : Trigger.New].Id;   

  // create some strings define criteria when the trigger fires
  for (Account acc: Trigger.New) {
  String corpacclink = acc.Corporate_Account_Link_Text__c;
  String mylink = 'My Link';
    if (corpacclink.contains(mylink))  
      {  
      //define what values to put against the new case
      newcase.add(new Case(
            AccountId = acc.Id,
            ContactId = personContact,
            RecordTypeId = rtId,
            Type='Welcome Call',
            Origin='Email',
            Status='Not Started',
            Call_Attempt__c='1'
            )
            );

      }
    
      //insert the new case(s)
      insert newcase;  
      }
  }

 

 

I understand WHY I am getting the error - the SOQL query looking for a Contact in line 14 isn't finding a Contact, because normal Accounts don't create Contacts (whilst Person Accounts do).

 

However - not sure how to fix this? Do I have to catch and handle the exception in some way? Or alternatively is there a way to get the trigger to only fire on Person Accounts?

 

Thanks!

Oh this seems so simple, yet I'm stuck!

 

Here's what I have now in my controller:

    public date d {
        get{
            d = date.today();
            return d;
            }
            set;
       }
    
    
    public List<event> all {
    get {
    all = [select subject, activitydate, location from Event where activitydate = :d Order By location ASC];
    return all;
    }
    set;
    }

 

All is peachy and the page loads up Today()'s info just fine.

 

Now, what I really want to do is load up the page initially with today's date and resulting info, but also have a button called "Next" that will add 1 day to the current date and update an outputPanel on my page with the new query results when clicked.

 

I know I need to add a function for the button action, but I'm not sure how to change the code above to manipulate the date variable accordingly.

 

Thanks in advance for any help you might provide!

I am cereating a button that will create a new task.  Is there a way to default the 'Due Date' to Today and also have the record automatically save?  I am using 'tsk4' to try and default due date but its not working. Here is my code.  Thanks

 

https://na5.salesforce.com/00T/e?who_id={!Account.Id}&what_id={!Opportunity.Id}
&RecordType=012700000005jvM&ent=Task
&tsk1_lkid={!Opportunity.OwnerId}
&tsk1={!Opportunity.OwnerFullName}
&tsk4 ={!TODAY()}
&tsk12=Completed
&tsk5=Call
&00N70000002OQDq=Left Message
&tsk6=Left Message
&Save=X

 

 

What are possible causes of the error message, "expired authorization code," when requesting an OAuth Access Token?

 

I'm testing the cookbook code at, "Interact with the Force.com REST API from PHP."
http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php

 

At oauth_callback.php, line 31, I seeing:

  • status: 400
  • error_uri: expired authorization code
  • error: invalid_grant
  • error_description: expired authorization code

Thanks.

Hi All,

 

I would like to be able to call the SF Metadata API from Apex code in my custom app.

 

I went to Setup/App Setup/Develop/API and clicked on 'Download Metadata WSDL' and saved it to my hard drive.

 

Then I went to Setup/App Setup/Develop/ApexClasses and clicked on the 'Generate from WSDL' button. For Step 1, I navigate to the Metadata WSDL that I just saved and click 'Parse WSDL.' This takes me to the Step 2 screen where I then click on the 'Generate Apex code' button.

 

This takes me to the Step 3 screen which shows this error:

 

<error>

Apex generation failed.

Error message:
Error: Class name 'Metadata' already in use. Please edit WSDL to remove repeated names

 

</error>

 

Does this error mean that what I am attempting to do is not allowed? If it is allowed, how do I get around this error.

 

Any help would be appreciated.

 

Thanks,

Andrew

Is that possible to retrieve metadata information about Tabs from apex code?

My use case:
-I have VisualForce Tab, wich is assigned to page.
-I need to redirect to that page from another page and highlight my tab at the same time.

I was able to investigate that for  custom tabs highlight functionality is implemented via query string parameters.Something like that:

?sfdc.tabName=01r40000000Dw3m&sfdc.motif=Custom53

So i need to query metadata (sfdc.tabName,sfdc.motif) to build proper PageReference instance before redirection.

Any help would be nice, thank you in advance.










Message Edited by vfDeveloper on 07-16-2008 04:26 AM