Error
This content is not currently supported on this browser.
+ Start a Discussion
Sandra OSandra O 
Hello - I am getting a Unekpected Token Illegal for my button to assign ownership to the person that clicks the button.

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

// identify the record 
var c = new sforce.SObject("Checklist__c"); 
c.id = "{!Checklist__c.Id}"; 

// make the field change 
c.Ownerid= {!$User.Id}; 


// save the change 
sforce.connection.update([c]); 

//refresh the page 
window.location.reload();
Best Answer chosen by Sandra O
Sandra OSandra O
Answered my own question...

I needed to change c.Ownerid= {!$User.Id}; to c.OwnerId="{!$User.Id}"
Dhaval PanchalDhaval Panchal 

Hello,

 

I want to delete 500+ custom fields. Is there any solution to mass remove custom fields? I have tried with metadata Api using below code. But it gives me below error.

 

Object with id:04s900000037qo4AAA is InProgress
Error status code: INVALID_CROSS_REFERENCE_KEY
Error message: In field: members - no CustomField named Custom_Field__c found
Object with id:04s900000037qo4AAA is Error

 

Below is the code:

 


    public void deleteCustomField(String fullname) throws Exception
    {
        CustomField customField = new CustomField();
        customField.setFullName(fullname);
        
        UpdateMetadata updateMetadata = new UpdateMetadata();
        updateMetadata.setMetadata(customField);
        updateMetadata.setCurrentName(fullname);
        
        AsyncResult[] asyncResults  = metadataConnection.delete(new Metadata[] {customField});
 
        long waitTimeMilliSecs = ONE_SECOND;
 
        do
        {
            printAsyncResultStatus(asyncResults);
            waitTimeMilliSecs *= 2;
            Thread.sleep(waitTimeMilliSecs);
            asyncResults = metadataConnection.checkStatus(new String[]{asyncResults[0].getId()});
        } while (!asyncResults[0].isDone());
 
        printAsyncResultStatus(asyncResults);
    }

 


    private void printAsyncResultStatus(AsyncResult[] asyncResults) throws Exception {
        if (asyncResults == null || asyncResults.length == 0 || asyncResults[0] == null) {
            throw new Exception("The object status cannot be retrieved");
        }

        AsyncResult asyncResult = asyncResults[0]; //we are creating only 1 metadata object

        if (asyncResult.getStatusCode() != null) {
            System.out.println("Error status code: " +
                    asyncResult.getStatusCode());
            System.out.println("Error message: " + asyncResult.getMessage());
        }

        System.out.println("Object with id:" + asyncResult.getId() + " is " +
            asyncResult.getState());
    }

 

Is there any other solution (any app) to removing custom fields?

 

Thanks in advance,

 

Dhaval Panchal

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Dhaval PanchalDhaval Panchal

Using ANT and SFDC Migration tool I am now able to delete bulk custom fields.

Download Apache Ant using below link:

Extract and copy this folder where you want to keetp (i have copied this folder to "C" drive : C:\apache-ant-1.9.2)
Set path in environment variables for ant.
To set environment variables
-> Right click on My Computer -> Property -> Advance System Setting -> Click on Environment variables button.
-> click on System variables -> Click on New -> Give variable name = ANT_HOME and variable value = [your and path]
see below images.


Now go to your salesforce account
click on
Setup -> Develop -> Tools -> Force.com Migration Tool.
Download "salesforce_ant_28.0" and extract this zip file.
You will file "ant-salesforce.jar" file in extracted folder, copy this
jar file to "C:\apache-ant-1.9.2\lib"

Now go to folder salesforce_ant_28.0 -> sample
open file "build.properties" and provide your username, password and token there.
In sample folder you will find xml file formates using that you can deploy components.

cnewmancnewman 
Hi Everyone,

Is there anyway I can have a confirmation box ask which action, from two options, I want to perform or cancel the operation?

I need a button on the Opportunity, that once pressed asks if you want to postone, close or cancel the action. First two options will change the status accordingly and the last will close the box and action nothing.

I'm familiar with the normal Yes/No confirmation box, not sure if this is possible?

Thanks
Chris
Best Answer chosen by cnewman
srlawr uksrlawr uk
If you check out this accepted answer on StackOverflow you'll see that in order to have a three button javascript alert box, you need to expand outside of native javascript support. JQuery libraries are easy to inlude in visualforce pages, and hopefully with a bit of tweeking the JS block provided in this answer will ive you what you want..

http://stackoverflow.com/questions/9091001/how-to-show-confirmation-alert-with-three-buttons-yes-no-and-cancel-as-it

I imagine (of course!) instead of just popping up an alert as to which button you pressed you are going to shoot off and do some apex remoting to call a controller method?
CW83CW83 
I have a javascript button I am trying to create to update a picklist field on a custom object.  Here is the code for the button:

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

var p = new sforce.SObject('Projects__c');
p.id = "{Projects__c.Id}";
p.Status__c = "Closed";
result = sforce.connection.update([p]);
location.reload(true);

The code is not throwing errors on the object it is just not updating the field.  The page is reloading. Anything wrong with the code?

Best Answer chosen by CW83
logontokartiklogontokartik
Looks like you missed "!" in your merge field it must be {!Projects__c.Id}. Also you can alert on result.message if you want to see any errors.
jud008jud008 

According to SOAP API Developer's Guide - Introducing SOAP API: Development Platforms different versions of the WSC tool can be obtained from http://code.google.com/p/sfdc-wsc/ and http://mvnrepository.com/artifact/com.force.api/force-wsc.

 

However, the latest version on the google-code site is wsc-22 whereas the latest on mvnrepository is wsc-26. On the other hand, the link to source code given on mvnrepository (http://github.com/forcedotcom/wsc) seems to be dead.


Which is which and which version should one use?

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

WSC is now available from its new home on Github https://github.com/forcedotcom/wsc

Kevin WrightKevin Wright 

I feel I'm almost there :)

 

The code below connects to the Salesforce server but ultimately fails with a 'no endpoint' exception.

 

I think I'm just not passing on the protocol credentials such as service and url endpoint to the object making the call,  but

I'm only guessing.

 

Also are there any pieces of sample code that make a WebService call from Java as I've not been able to find any?

 

Can anyone help me please?

 

 

 

import com.sforce.soap.schemas._class.MyWebService.*;
import java.net.*;
import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.ExceptionCode;

 

public class TestCall{

 

 public static void main(String[] args){

                LoginResult loginResult;

  System.out.println("start of program");
  try{

  SoapBindingStub bind=  (SoapBindingStub) new SforceServiceLocator().getSoap();
                System.out.println("after call to getSoap()");
  bind.setTimeout(60000);

   
  loginResult = bind.login("myadminuser", "mypassword");
  System.out.println("straight after login call");
  bind._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());

    com.sforce.soap.enterprise.SessionHeader sh = new com.sforce.soap.enterprise.SessionHeader();
          sh.setSessionId(loginResult.getSessionId());
      
   
         bind.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
                          "SessionHeader", sh);
       
              

   MyWebServiceBindingStub stub = new MyWebServiceBindingStub();

   

   System.out.println("about to make call");
   stub.myMethod();
  }
    catch (LoginFault ex) {
            // The LoginFault derives from AxisFault

            ExceptionCode exCode = ex.getExceptionCode();
            System.out.println("######" + exCode);
            if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED ||
                exCode == ExceptionCode.INVALID_CLIENT ||
                exCode == ExceptionCode.INVALID_LOGIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME ||
                exCode == ExceptionCode.ORG_LOCKED ||
                exCode == ExceptionCode.PASSWORD_LOCKOUT ||
                exCode == ExceptionCode.SERVER_UNAVAILABLE ||
                exCode == ExceptionCode.TRIAL_EXPIRED ||
                exCode == ExceptionCode.UNSUPPORTED_CLIENT) {
                System.out.println("Please be sure that you have a valid username " +
                     "and password.");
            } else {
                // Write the fault code to the console

                System.out.println(ex.getExceptionCode());
                // Write the fault message to the console

                System.out.println("An unexpected error has occurred." + ex.getMessage());
            }
  

  }
   catch(Exception e){
   System.out.println("error" + e.getMessage());
  }

 }

 


}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Kevin WrightKevin Wright

Success!! The following code sucessfully calls an Apex Web Service from Java. The System log indicates the call is being

made. I am sure there is a certain amount of duplication of operations in this code and it needs cleaning up. But it does work! :smileyhappy:

 

 

 

 

 

import com.sforce.soap.schemas._class.MyWebService.*;
import java.net.*;
import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.ExceptionCode;

 

public class TestCall{

 

 public static void main(String[] args){

                LoginResult loginResult;

  System.out.println("start of program");
  try{

  SoapBindingStub bind=  (SoapBindingStub) new SforceServiceLocator().getSoap();
                System.out.println("after call to getSoap()");
  bind.setTimeout(60000);


  loginResult = bind.login("adminusername", "adminpassword");
  System.out.println("straight after login call");
  bind._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());

    com.sforce.soap.enterprise.SessionHeader sh = new com.sforce.soap.enterprise.SessionHeader();
          sh.setSessionId(loginResult.getSessionId());


         bind.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
                          "SessionHeader", sh);

   MyWebServiceServiceLocator locator = new MyWebServiceServiceLocator();

   //************ new stuff here.
      //ApexWebServiceTestService svc = new ApexWebServiceTestServiceLocator();

      java.net.URL url = new java.net.URL(locator.getMyWebServiceAddress());

   MyWebServiceBindingStub stub = new MyWebServiceBindingStub(url, locator);


              //SessionHeader sh = new SessionHeader();
              //sh.setSessionId(sessionId);

          String sforceURI = locator.getMyWebServiceAddress();
              stub.setHeader(sforceURI, "SessionHeader", sh);


   // ***********end of new stuff


   System.out.println("about to make call");
   stub.myMethod();
  }
    catch (LoginFault ex) {
            // The LoginFault derives from AxisFault

            ExceptionCode exCode = ex.getExceptionCode();
            System.out.println("######" + exCode);
            if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED ||
                exCode == ExceptionCode.INVALID_CLIENT ||
                exCode == ExceptionCode.INVALID_LOGIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME ||
                exCode == ExceptionCode.ORG_LOCKED ||
                exCode == ExceptionCode.PASSWORD_LOCKOUT ||
                exCode == ExceptionCode.SERVER_UNAVAILABLE ||
                exCode == ExceptionCode.TRIAL_EXPIRED ||
                exCode == ExceptionCode.UNSUPPORTED_CLIENT) {
                System.out.println("Please be sure that you have a valid username " +
                     "and password.");
            } else {
                // Write the fault code to the console

                System.out.println(ex.getExceptionCode());
                // Write the fault message to the console

                System.out.println("An unexpected error has occurred." + ex.getMessage());
            }


  }
   catch(Exception e){
   System.out.println("error" + e.getMessage());
  }

 }


}

Ronnie Paton 8Ronnie Paton 8 
Hi All,

I am trying to create a button that converts a case to an opportunity, but have ran into a bit of a brickwall

When I click the button I get the following error

 A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:,soapenv:Client',faultstring:"03/08/2014' is not a valid value for the type xsd:date',}


The status of the case changes but the opportunity is not created, here is the code I have but not sure if it works totally as can't get past the date issue.

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
   caseObj.Id = '{!Case.Id}';
   caseObj.Status = 'Converted to Opportunity';
var result = sforce.connection.update([caseObj]);
var status = "{!Case.Status}}";
var newRecords = [];
{
   var o = new sforce.SObject("Opportunity");
   o.AccountId = '{!Case.AccountId}';
   o.Type = '{!Case.Type}';
   o.Name = '{!Case.CaseNumber},{!Case.Subject}';
   o.LeadSource = '{!'Converted from Case'}';
   o.Description = '{! Case.Description }';
   o.OwnerId = '{!Account.OwnerId}';
   o.StageName = '{!'Perception Analysis'}';
   o.CloseDate = '{! TODAY() +30}';
newRecords.push(o);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
    parent.ID = '{!Case.ParentId}';
    window.parent.location = ('/00a/e?parent_id=retURL=/{!Case.Id}');}


I know the issue is from the o.CloseDate = '{! TODAY() +30}'; but just can't workout what it should be.

Thanks
 
Best Answer chosen by Ronnie Paton 8
Jim JamJim Jam
try this ..

    dt = new Date();
    dt.setDate(dt.getDate() + 30);
    o.CloseDate =  dt;
Daniel Gonzalez TorresDaniel Gonzalez Torres 
I am trying the version 31.0 of the metadata api. There is a new async method checkRetrieve status that accepts an asyncRetrieveId (e.g. 09SK0000001DmPTMA0) but my program throws an exception when I check for the tretrieve status.

I'm trying to retrieve a couple of Apex Classes (already in v31.0).

This is the exception I get:

com.sforce.ws.ConnectionException: Unexpected element. Parser was expecting element 'http://soap.sforce.com/2006/04/metadata:done' but found 'http://soap.sforce.com/2006/04/metadata:fileProperties'
	at com.sforce.ws.bind.TypeMapper.verifyTag(TypeMapper.java:389)
	at com.sforce.ws.bind.TypeMapper.verifyElement(TypeMapper.java:418)
	at com.sforce.soap.metadata.RetrieveResult.loadFields(RetrieveResult.java:237)
	at com.sforce.soap.metadata.RetrieveResult.load(RetrieveResult.java:230)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:631)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:507)
	at com.sforce.soap.metadata.CheckRetrieveStatusResponse_element.loadFields(CheckRetrieveStatusResponse_element.java:62)
	at com.sforce.soap.metadata.CheckRetrieveStatusResponse_element.load(CheckRetrieveStatusResponse_element.java:54)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:631)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:507)
	at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:174)
	at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:148)
	at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:99)
	at com.sforce.soap.metadata.MetadataConnection.checkRetrieveStatus(MetadataConnection.java:229)
	at com.force.deploy.tools.MainUIController.processApex(MainUIController.java:683)



Best Answer chosen by Daniel Gonzalez Torres
Daniel Gonzalez TorresDaniel Gonzalez Torres
Found a workaround: I manipulated the metadata.xml (wsdl) and changed the RetrieveResult to the old version.

Changed from:

<xsd:complexType name="RetrieveResult">
    <xsd:sequence>
     <xsd:element name="done" type="xsd:boolean"/>
     <xsd:element name="errorMessage" minOccurs="0" type="xsd:string"/>
     <xsd:element name="errorStatusCode" minOccurs="0" type="tns:StatusCode"/>
     <xsd:element name="fileProperties" minOccurs="0" maxOccurs="unbounded" type="tns:FileProperties"/>
     <xsd:element name="id" type="xsd:string"/>
     <xsd:element name="messages" minOccurs="0" maxOccurs="unbounded" type="tns:RetrieveMessage"/>
     <xsd:element name="status" type="tns:RetrieveStatus"/>
     <xsd:element name="success" type="xsd:boolean"/>
     <xsd:element name="zipFile" type="xsd:base64Binary"/>
    </xsd:sequence>
   </xsd:complexType>

to:

<xsd:complexType name="RetrieveResult">
    <xsd:sequence>
     <xsd:element name="fileProperties" minOccurs="0" maxOccurs="unbounded" type="tns:FileProperties"/>
	 <xsd:element name="id" type="xsd:string"/>
     <xsd:element name="messages" minOccurs="0" maxOccurs="unbounded" type="tns:RetrieveMessage"/>
	 <xsd:element name="zipFile" type="xsd:base64Binary"/>
    </xsd:sequence>
   </xsd:complexType>


David OvellaDavid Ovella 
Hello, I need a lot of help.
Is it possible change the images of the login page?
and if I can, how?
User-added image
Best Answer chosen by David Ovella
Sagar PareekSagar Pareek
Take a look at this 

https://help.salesforce.com/apex/HTViewHelpDoc?id=domain_name_login_branding.htm&language=en_US
Ronnie Paton 8Ronnie Paton 8 
HI,

I am trying to create a custom button on a custom Object that when clicked creates Account\Contact\Opportunity (like convert button on Lead).

The code I have is 
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var ProspectObj = new sforce.SObject("Prospect__c"); 
   ProspectObj.ID = '{!Prospect__c.Id}';   
   ProspectObj.Converted__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+0);
   Prospect__c.Converted_Date__c = dt;
var result = sforce.connection.update([ProspectObj]);
var status = "{!Prospect__c.Status__c}";
var newRecords = [];
{
   var acct = new sforce.SObject("Account");
   acct.OwnerId = '{!Prospect__c.OwnerId}';
   acct.Name = '{!Prospect__c.Name}';
   acct.ShippingStreet = '{!Prospect__c.Street__c}';
   acct.ShippinggCity = '{!Prospect__c.City__c}';
   acct.ShippingState = '{!Prospect__c.State__c }';
   acct.ShippingPostalCode = '{!Prospect__c.Postcode__c}';
newRecords.push(acct);
}
var result = sforce.connection.create(newRecords);

var newRecords = [];
{
   var opp = new sforce.SObject("Opportunity");
   opp.AccountId = '{!Account.Id}';
   opp.OwnerId = '{!Prospect__c.OwnerId}';
   opp.Name = '{!Prospect__c.Description__c}';
   opp.LeadSource = 'Converted from Prospect';
   opp.StageName = 'Perception Analysis';
   opp.Type = 'New Business';
   opp.Prospect_First_Contact_Made__c = 'True';
   opp.Prospect_Initial_Meeting_Scheduled__c = 'True';
   opp.Prospect_Opportunity_Identified__c = 'True';
   opp.Prospect_Requirements_Documented__c = 'True';
   opp.Qualified_Need_to_Buy_Confirmed__c = 'True';
   dt= new Date();
   dt.setDate(dt.getDate()+30);
   opp.CloseDate = dt;
newRecords.push(opp);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
   window.parent.location = '/a05?fcf=00Bb0000003wFhp';
}

when I click the button I get an error saying that Prospect__c is not defined.

Any pointers would be a great help.

Thanks in Advance

Ronnie

 
Best Answer chosen by Ronnie Paton 8
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

Try changing this line:
 
// original code   
Prospect__c.Converted_Date__c = dt;

// change to
ProspectObj.Converted_Date__c = dt;

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.