• dphill
  • NEWBIE
  • 190 Points
  • Member since 2012

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 62
    Replies

I'm trying to write a trigger that fills in a custom lookup field on a case by looking for a custom object with an exact match in a text field.

 

Basically, what I would like to do is when the custom object (custobj) is created or saved, and the text field (Package ID) has a value, find all cases with the same value in an equivalent custom field, and add the custom object to a lookup field on the case.

 

All attempts at writing this run into the same issue which is how to form the SOQL query to pull the related cases to update.  The following query is obviously totally wrong, but hopefully it highlights where my problem is.  What I think I need to do is pull all cases that have the Package_ID__c field which matches a Package_ID__c field on the custom object.  Can anyone help clarify how to do this?

 

List<Case> cases = new List<Case>([SELECT Id, Package_ID__c FROM Case WHERE Package_ID__c = custobj.Package_ID__c);

Thanks!!

  • September 13, 2013
  • Like
  • 0

After having made changes in the edit window to the APEX code connected to the page, I attempted to return to the IDE to make changes to the controller class but updating the server failed. The instruction was to Synchronize the Perspective. Where is the command for this? I only see 'customize','save' and 'reset Perspective in the 'Window' drop down menu.

Hi guys,

 

My question is more related to SOQL querying via a query editor rather than using SOQL in Apex.

 

Below is my query and when I run this query through a query editor such as Force.com explore or Real Force Explore the result set that comes back displays the record count for the sub query which you have to click on in order to see the actual records returned.

 

SELECT SFSSDupeCatcher__Duplicate_Warning_Count__c, Name, SFSSDupeCatcher__Scenario_Rule_Count__c, SFSSDupeCatcher__Scenario_Type__c, SFSSDupeCatcher__Potential_Duplicate_Count__c, (Select Name From SFSSDupeCatcher__Scenario_Rules__r) FROM SFSSDupeCatcher__Scenario__c

 

Is there any way to display a Parent-Child's sub query results also in the query results that are returned? I need to be able to export all results to a .csv file.

 

Thanks in advance for any help that you can give me with this.

<apex:page controller="AccountExample1" showHeader="true" action="{!ActionToDo}">
    <apex:form >
        <apex:sectionHeader title="New Account" subtitle="Edit Account" />
        
        <apex:pageBlock title="Account Edit" mode="Edit">
            
                <apex:pageBlockSection title="Account Information">
                    <apex:outputField value="{!acc.ownerID}"/>
                    <apex:inputField value="{!acc.Rating}"/>
                    <apex:inputField value="{!acc.Name}"/>
                    <apex:inputField value="{!acc.Phone}"/>
                    <!--<apex:inputField value="{!acc.Parent}"/>-->
                    <apex:inputField value="{!acc.Fax}"/>
                    <apex:inputField value="{!acc.AccountNumber}"/>
                    <apex:inputField value="{!acc.Website}"/>
                    <apex:inputField value="{!acc.Site}"/>
                    <apex:inputField value="{!acc.TickerSymbol}"/>
                    <apex:inputfield value="{!acc.Type}"/>
                    <apex:inputField value="{!acc.OwnerShip}"/>
                    <apex:inputField value="{!acc.Industry}"/>
                    <apex:inputfield value="{!acc.NumberOfEmployees}"/>
                    <apex:inputfield value="{!acc.AnnualRevenue}"/>
                    <apex:inputField value="{!acc.sic}"/>
                    <apex:inputField value="{!acc.Account_Email__c}" />
                    <apex:inputField value="{!acc.Count_Contacts__c}"/>
                    
                </apex:pageBlockSection>     
                <apex:pageBlockSection title="Account Information" >
                    <apex:inputTextarea value="{!acc.BillingStreet}"/>
                    <apex:inputTextarea value="{!acc.ShippingStreet}"/>
                    <apex:inputField value="{!acc.BillingCity}"/>
                    <apex:inputField value="{!acc.ShippingCity}"/>
                    <apex:inputfield value="{!acc.BillingState}"/>
                    <apex:inputField value="{!acc.ShippingState}"/>
                    <!--<apex:inputField  value="{!acc.BillingZip}"/>-->
                    <!--<apex:inputField value="{!acc.ShippingZip}"/>-->
                    
                
                </apex:pageBlockSection>
            <apex:pageBlockSection title="Account Information">
                <apex:inputfield value="{!acc.CustomerPriority__c}"/>
                <apex:inputField value="{!acc.SLA__c}"/>
                <apex:inputField value="{!acc.SLAExpirationDate__c}"/>
                <apex:inputField value="{!acc.SLASerialNumber__c}"/>
                <apex:inputField value="{!acc.NumberofLocations__c}"/>
                <apex:inputField value="{!acc.UpsellOpportunity__c}"/>
                <apex:inputField value="{!acc.Active__c}"/>
            
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Description Information">
                <apex:inputtextarea value="{!acc.Active__c}"/ >
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!Save}" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

 

 

 

 

 

public class AccountExample1
{
    public void Save() {
     //acc = new Account();
        insert acc;
    }

    public AccountExample1()
    {
       
        //acclist = [Select * from Account];
    }
    
    public Account acc{set;get;}
    //public List<Account> acclist{set;get;}
    public void ActionToDo()
    {
    }
}

I am running into a deployment error with a test class which runs fine in the sandbox.  The error I am receiving is Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, QuoteAdoptionAgreementSent: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 0Q0600000005hI8CAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY


The line and column from the test class that it is hanging on is the insertion of a task.  My test class is as follows and the line getting the error is Line 23.  I've checked my system admin profile and it has access to everything.  I can't figure this out.  Please help.

 

Thank you,

Amanda

 

@IsTest
private class TestQuoteAASentUpdateOppCreateCourses
{
    private static TestMethod void testTrigger(){
        
        //Step 1 : Data Insertion
        Account a=new Account(Name='Test Account');
           insert a;
           Contact c = new Contact(FirstName='John',LastName='Doe');
        insert c;
        Opportunity o = new Opportunity(Name='Test Opportunity',closedate=system.today(), stagename='Confirmed Teaching/Class Schedule',Probability=0.95);
        insert o;      
        OpportunityContactRole ocr = new OpportunityContactRole (OpportunityID = o.id, ContactID=c.id, role='Decision Maker') ;     
        insert ocr;  
        Quote q= new Quote (Name='Test Quote', ContactID=c.id, OpportunityID=o.id);
        insert q;
        
        
        test.startTest();
        
        //Perform the dml action on which trigger gets fired , like insert, update ,delete , undelete, in your case you have to update account record that you created in above  
       Task t= new Task (Subject='Email: Sapling Learning Adoption Agreement', WhoID=c.id, WhatID=q.id);
        insert t;
       
       
        // Switch back to runtime context
        Test.stopTest();
        
    }
}

I'm trying to test my visualforce controller but so far I'm just not seeing how to change example testcontrollers I see out there to fit my simple controller.  My controller is just

Public with Sharing Class Courseinlineedit {
    Private Final Opportunity opp;
    Public CourseInLineEdit (Apexpages.StandardController Stdcontroller)
    {
        this.opp= (Opportunity)Stdcontroller.getrecord();

        FirstCourses = [select ID, Name,Contact__c, Chapters_ish__c,First_Tech_TA_Contact__c, Course_Delivered__c ,TA_Notes__c, Key_Code_Info__c, Adoption_Agreement__c from Course__c where Opportunity__c= :this.opp.id order by Name];
    }
    public list<Course__c> FirstCourses{get;set;}

    public pagereference updateListItems()
    {
        if(GlobalHelper.CheckForNotNull(FirstCourses))
        {
            List<database.saveresult> saveResults = database.update(FirstCourses);
        }
        return null;
    }
}

 

 

but all I have so far for my test class is a mess that doesn't even save, n/m test what my controller is doing.

 

public class CourseinlineeditTests {

    public static testMethod void testMyController() {
        PageReference pageRef = Page.Courseinlineedit;
        Test.setCurrentPage(pageRef);
      
        thecontroller controller = new thecontroller();
        String nextPage = controller.save().getUrl();

        // Verify that page fails without parameters
        System.assertEquals('/apex/failure?error=noParam', nextPage);

        
         //Step 1 : Data Insertion
        Account a=new Account(Name='Test Account');
           insert a;
           Contact c = new Contact(FirstName='John',LastName='Doe');
        insert c;
        Opportunity o = new Opportunity(Name='Test Opportunity',closedate=system.today(), stagename='Confirmed Teaching/Class Schedule',Probability=0.95);
        insert o;      
        OpportunityContactRole ocr = new OpportunityContactRole (OpportunityID = o.id, ContactID=c.id, role='Decision Maker') ;     
        insert ocr;  
        Quote q= new Quote (Name='Test Quote', ContactID=c.id, OpportunityID=o.id);
        insert q;
        Course__c newCS = new Course__c (Adoption_Agreement__c=q.id, Opportunity__c=o.id, Contact__c=c.id);

        // Add parameters to page URL
        ApexPages.currentPage().getParameters().put(o.id);
      
        // Instantiate a new controller with all parameters in the page
        controller = new Courseinlineedit();
        controller.setOpportunity(o.id);
        nextPage = controller.save().getUrl();

        // Verify that the Courseinlineedit page displays
        System.assertEquals('/apex/Courseinlineedit', nextPage);
    }
    }

Hi,

Please help to create a unit test for my trigger.

 

 

I having a trouble deploying my trigger in productio since sfdc is requiring a unit test. please help me. sandbox do not require a unit test. please please, im clueless onhow to start the unite tes.

 

here's the code:

=====

 

trigger UpdateQuoteManagers on Quote (before insert, before update) {
Set<ID> idOwners = new Set<ID>();


for(Quote quotes:trigger.new)
{
idOwners.add(quotes.Account_Manager__c);
}

if (idOwners.size() > 0)
{
Map<Id,User> users= new Map<Id,User>([Select Territory_Head__c, District_Head__c from User where Id in : idOwners]);

for(Quote qu:trigger.new)
{

if (users.get(qu.Account_Manager__c).Id!= null)
{
qu.District_Head2__c = users.get(qu.Account_Manager__c).District_Head__c;
qu.Territory_Head2__c = users.get(qu.Account_Manager__c).Territory_Head__c;
}
else
{
qu.District_Head2__c = null;
qu.Territory_Head2__c = null;

}
}
}
}

I'm trying to write a trigger that fills in a custom lookup field on a case by looking for a custom object with an exact match in a text field.

 

Basically, what I would like to do is when the custom object (custobj) is created or saved, and the text field (Package ID) has a value, find all cases with the same value in an equivalent custom field, and add the custom object to a lookup field on the case.

 

All attempts at writing this run into the same issue which is how to form the SOQL query to pull the related cases to update.  The following query is obviously totally wrong, but hopefully it highlights where my problem is.  What I think I need to do is pull all cases that have the Package_ID__c field which matches a Package_ID__c field on the custom object.  Can anyone help clarify how to do this?

 

List<Case> cases = new List<Case>([SELECT Id, Package_ID__c FROM Case WHERE Package_ID__c = custobj.Package_ID__c);

Thanks!!

  • September 13, 2013
  • Like
  • 0

Hi ,

I am looking at apex code to check thro triggers check if the record already exists  and display an error.

 

Suppose on Contact record  wanted to check  if Name+ email+phone exists then display an error to the user that duplicate record.

 

Is there any sample code anyone can share with me?

 

thanks

K

  • September 13, 2013
  • Like
  • 0

Hi,

I have a trigger on Opportunity which fires once opportunity stage = closed won. My Test method passes but shows error on class?

 

/*
Author: Mahfuz Choudhury
Date: 13.09.13
TestClassName:TestCloneOppLineItem on Opportunity
*/
@isTest(seeAllData=true) 
private class TestCloneOppLineItem{
    static testMethod void TestOppMethod() {
        List<Contact> contlist = new List<Contact>{};
        
        //Start of the test execution
        Test.starttest();
        //create a new account to associate with the opportunity
        Account a = new Account(Name = 'Test Account');
        insert a;
        
        //Create a contact to assign as primary contact role
        Contact con = new Contact(FirstName = 'Maf', LastName = 'Sample', AccountId = a.Id);
        Contact con1 = new Contact(FirstName = 'Lewis', LastName = 'Test', AccountId = a.Id);
        contlist.add(con);
        contlist.add(con1);
        insert contlist;
        
        //Select A Standard pricebook for the product
        Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];
        
        //Create a Test PriceBook for OpportunityLineItem
        Pricebook2 pbk = new Pricebook2 (Name='Test Pricebook Entry 1',Description='Test Pricebook Entry 1', isActive=true);
        insert pbk;
        
        //Insert a new Product for test class
        Product2 prd = new Product2 (Name='Premium Product',Description='Test Product Entry 1',productCode = 'ABC', isActive = true);
        insert prd;
        
        //Insert a new Pricebook entry
        PricebookEntry pbe = new PricebookEntry (Product2ID=prd.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true,UseStandardPrice=false);
        insert pbe;
        
        //create a new opportunity to test
        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opportunity';
        Opp.AccountId = a.id;
        Opp.StageName = 'Closed Won';
        Opp.Type = 'Existing Business';
        Opp.CloseDate =  Date.today()+2;
        insert opp;
        
        OpportunityLineItem OLI = new OpportunityLineItem();
        OLI.Quantity = 2;
        OLI.UnitPrice = 5.00;
        OLI.OpportunityId = Opp.id;
        //OLI.ProductId = pbe.Id;
        OLI.PricebookEntryId = pbe.id;
        insert OLI;
        
        //creating opportunity contact role and make it primary
        OpportunityContactRole ocr = new OpportunityContactRole(OpportunityId = Opp.Id, ContactId = Con.Id, IsPrimary = true);
        insert ocr;
        
        System.assertEquals('Closed Won',Opp.StageName);
        System.assertEquals(Opp.IsOnlineOrder__c, false);
        
        Opp.IsOnlineOrder__c = true;
        Update Opp;
        System.assertEquals(Opp.IsOnlineOrder__c, true);
        Test.stopTest();
    }
}

 Can I get some help on this plz...

  • September 13, 2013
  • Like
  • 0

with sharing with out sharing, Which is the default in Apex class?????????

 

please help me....

  • September 13, 2013
  • Like
  • 0

I am obviously missing something obvious, but this query just doesn't work, and i can't work out why, can somebody assist?

 

SELECT Id,Name,Amount,R2_Job_Ref__c,R2_Shipping_Post_Code__c,Shipping_Postcode_2__c
FROM Opportunity
WHERE Shipping_Postcode_2__c != R2_Shipping_Post_Code__c AND R2_Shipping_Post_Code__c != null

 

Thanks!

 

Gareth

I wrote a simple class, and have a test method which in the Force.com IDE is telling me covers this class 100%.  When I right-click on the class in the Package Explorer, go to Force.com > Deploy to server... I enter my production credentials and they are validated, then I see that only my class is set to add to the production environment and I go forward with the deployment.

After several minutes, I get a FAILURE message related to one test along the lines of 'too many DML rows', looking into the logs I see there are 10283 rows which exceeds the limit of 10000.  I log in to the production environment and run the failing test, and it fails in production too WITH THE SAME ERROR.

Now I have a chicken/egg situation and I don't know how to get any code to production with this failing test, and furthermore, I don't know how anything that would have broken this test would have made it to production!  I tried locally commenting out everything in the test class and the deployment failed in the exact same way (to the character) so I know it is not anything locally that I need to change.  I did have to fix some things in the test to get it to run locally, but that is irrelevant here especially since I commented the entire body out and got the same error.

HELP!!

Class I'm trying to deploy:

public class AuthorizationToken {

public String LoginId;

public String Password;

public AuthorizationToken(String user, String pw)

{

Password = pw;

LoginId = user;

}

statictestMethodvoid testAuthTokenInstantiation()

{

String user = 'testUser';

String pw = 'testPw';

Test.startTest();

AuthorizationToken testAuthToken = new AuthorizationToken(user, pw);

Test.stopTest();

System.assertEquals(testAuthToken.LoginId, 'testUser');

}

}

FAILING TEST CLASS:

@isTest
public with sharing class generateRenewalOppty_TEST
{
    static testMethod void myTest()
    {
        Boolean success = true;
       
       
           
            Account testAccount = new Account();
            testAccount.Name = 'Test';
            testAccount.Phone = '1111111111';
            testAccount.County__c = 'Macomb';
            testAccount.Member_Payment_Form__c ='Standard - Cash';
            testAccount.Type = 'Membership - New';
        
            insert testAccount;
           
            update testAccount;
           
            Product2 testProduct2 = new Product2(Name='TestProduct', ProductCode = '123', IsActive = true);
            insert testProduct2;
           
            List<Pricebook2> testPB2List = [select Id from Pricebook2 where IsStandard = true];
           
            PricebookEntry testPBE = new PricebookEntry(Product2Id = testProduct2.Id, Pricebook2Id = testPB2List[0].Id, UnitPrice = 5.0, UseStandardPrice = false, IsActive = true);
            insert testPBE;
           
           
            Opportunity oppObj = new Opportunity(Name='Test Opp',StageName='Closed Won - In-Kind',CloseDate=System.Today(),AccountId=testAccount.Id, type='Membership - New');
            insert oppObj;
           
            OpportunityLineItem testOPL = new OpportunityLineItem(OpportunityId = oppObj.Id, Quantity = 1.0, TotalPrice = 100, PricebookEntryId = testPBE.Id);
            insert testOPL;
           
            OpportunityLineItem testOPL1 = new OpportunityLineItem(OpportunityId = oppObj.Id, Quantity = 1.0, TotalPrice = 100, PricebookEntryId = testPBE.Id);
            insert testOPL1;
           
        
            testAccount.Generate_Renewal_Oppty__c = true;
            update testAccount;
          
            Opportunity[] oppOpen =[Select Id,Amount from Opportunity Where (StageName='Open' or StageName='Membership - Renewal') and AccountId =:testAccount.Id];
            System.assertEquals(1, oppOpen.size());
          
            OpportunityLineItem[] oppLi =[Select Id,TotalPrice from OpportunityLineItem Where OpportunityId=:oppOpen[0].Id];
            System.assertEquals(2, oppLi.size());
            System.assertEquals(100, oppLi[0].TotalPrice);
            System.assertEquals(100, oppLi[1].TotalPrice);
           
            Opportunity[] oppRec = [Select Id from Opportunity];
            delete oppRec;
           
            Opportunity oppOb = new Opportunity(Name='Test Opp1',StageName='Open',CloseDate=System.Today(),AccountId=testAccount.Id);
            insert oppOb;
           
            testAccount.Generate_Renewal_Oppty__c = true;
            update testAccount;
           
            Opportunity[] oppRec1 = [Select Id from Opportunity];
THIS IS LINE 52: delete oppRec1;
           
            Opportunity oppOb1 = new Opportunity(Name='Test Opp1',StageName='Open',CloseDate=System.Today(),AccountId=testAccount.Id,Type = 'Membership - New');
            insert oppOb1;
           
            testAccount.Generate_Renewal_Oppty__c = true;
            update testAccount;
           
            //delete oppOpen;
                      
        }
 
}


TEST RESULT DETAIL:

Class: generateRenewalOppty_TEST

Method Name: myTest

Pass/Fail: Fail

Error Message: System.LimitException: Too many DML rows: 10001

Stack Trace: Class.generateRenewalOppty_TEST.myTest: line 52, column 1

 

Hi Everyone,

 

I have a text file that is uploaded by the user,

Using the Document class,

 

How can i read the content of that text file,

ex: Name, address, email, ...etc,

 

I want to save those paramters to an object i have created,

 

Is it possible to open and read an uploaded text file with VisualForce or Apex?

 

Thanks 

hi,

iam new to use field set in visualforce page

i created a one field set to retrive to vf page iam getting the error!

 

 

 

<apex:page controller="fieldset1">
    <apex:form >
        <apex:pageBlock title="Field Set List">
            <apex:pageBlockSection >
            <apex:repeat value="{!$ObjectType.cr__c.Fieldsets.Myfieldset}"/>
             <apex:inputField value="{!cr__c[f]}"/>   
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

iam did not get the field in vf page

ERROR::Invalid identifier: cr__c

 

 

 

 

Hi I'm new developing appex triggers and i can't make a trigger to work

 

I have to update a field on a custom object called pse__Timecard_Header__c The problem is that the field to update is a lookup field

 

  1. This field to be updated is: Manager__c  
  2. The manager info is located in the salesforce standard object caled "User" and the field name is called "Manager"

The Problem is that there is no direct link between the "user" object and my custom object called "timecard"

There is a looup field at the timecard to a custom "contact"  and from the contact there is a direct link to the salesforce "User"

 

 Summary: Timecard -> Contact -> Salesforce User

 

Thanks!!

 

Pablo

 

 

Hi,

I have code below, I wish to know how to get value of individual fields instead of using it like values() from map.

 

CODE:

 

for(Case c:caseemlist) {
for(EmailMessage em:c.EmailMessages) {
Emailmessage message = new Emailmessage (fromname = em.fromname,subject = em.subject,textbody = em.textbody,htmlbody = em.htmlbody,toaddress = em.toaddress,
fromaddress = em.fromaddress,ccaddress = em.ccaddress,status = em.status,messagedate = em.messagedate,ParentId=oldnewCaseIdmap.get(c.id));
//emlisttoinsert.add(message);
emailMessageMap.put(em.Id, message);
}
}

Attachment[] attList = new list <Attachment>();
Attachment[] insertAttList = new list <Attachment>();
if(emailMessageMap.values().size()>0) {
insert emailMessageMap.values();

 

Example in above, i wsh to insert individual values like fromaddress, ccaddress, how do i do it, i dont want to use values().

 

Hi,

 

I'm new in salesforce, I code something that working well but I can't make working the test method. When I call the "iWantMyJSValues" function I've got "Argument 1 cannot be null".

 

public withsharingclass CourseController {

 

privatefinalCourse__c course;   

private ApexPages.StandardController con ;   

   

public CourseController(ApexPages.StandardController controller) {

      con = controller;

      this.course = (course__c)controller.getRecord();   

   }

   

   public String valueOne { get; set; }

    integer i;

   

   

    public PageReference iWantMyJSValues() {

   

          valueOne = Apexpages.currentPage().getParameters().get('one');

           i = integer.valueof(valueOne);

   

    

if (i == 0) {    

this.course.v_end__c = this.course.v_end__c + i;

     } Else if (i == 1) {

this.course.v_start__c = this.course.v_start__c + i;

     } Else if (i == 2) {    

this.course.v_pause__c = this.course.v_pause__c + i;

     }

   

update course;

       

returnnull;

 }

   

public static testmethod void testiWantMyJSValues(){

 

    list<Course__c> courses = newlist<Course__c>{};

    Course__c testCourse = newCourse__c();

     testCourse.Language__c = 'English';

     testCourse.Training_Format__c ='On Demand';

     testCourse. Course__c = 'a0Ea000000J0G1e';

     courses.add(testCourse);

     insert courses;

 

ApexPages.StandardController to = new ApexPages.StandardController(testCourse) ;

 

CourseController controller = new CourseController(to) ;

Controller.iWantMyJSValues();

 

}

 

 

}

Hi,

 

Basically i have a task to create a batch which works if User select Startdate and enddate of data to be deleted please guide me how can i start 

Does anyone have experience with sending text messages out of salesforce by asking for the user's email address that their carrier turns into a text message and then sends (and bills for)?

 

Any one know an easier way to do that?

 

tia

Right now I'm just trying to establish a connection between my java app and Salesforce, but it isn't working out very well.  For some reason on my connection = new PartnerConnection(config); line I always error.

 

[ApiFault  exceptionCode='INVALID_LOGIN' exceptionMessage='Invalid username, password, security token; or user locked out.'

 

I have already confirmed that my username/password/security token are all correct.

 

public static void main(String[] args)  {   

ConnectorConfig config = new ConnectorConfig();   

config.setUsername("MYLOGIN");   

config.setPassword("MYPW&MYTOKEN");       

PartnerConnection connection;

try    {        

connection = Connector.newConnection(config);  

 } catch (ConnectionException e)    {     

// TODO Auto-generated catch block      e.printStackTrace();    }   }