-3
/** * An apex page controller that exposes the site login functionality */
@IsTest global with sharing class  DisplaySuppliersDetailsFormTest {    
@IsTest(SeeAllData=true) global static void testDisplaySuppliersDetailsForm () {
 //Insert The accounts
        List<Account> accts = new List<Account>();

            for(Integer i=0;i<10;i++)
             {
                Account a = new Account(Name='TestAccount' + i, 
                                        BillingCity ='Kolkata',
                                        BillingCountry ='India',
                                        BillingPostalCode='560048',
                                        BillingState='Kolkata',
                                        Phone='8904145771',
                                        BillingStreet='Starlit Housing Complex');

                accts.add(a);
            }
    insert accts;
   //Insert The corresponding Contacts

    List<Contact> cons = new List<Contact>();
    for (Integer j=0;j<10;j++) {
        Account acct = accts[j];            
        // For each account just inserted, add contacts
        for (Integer k=2*j;k<2*(j+1);k++) {
            cons.add(new Contact(firstname='Test'+k,
                                 lastname='Test'+k,
                                 AccountId=acct.Id));
        }
    }
    // Insert all contacts for all accounts
    insert cons;
    //Insert the test user
    Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
    User u = new User(Alias = 'standt', Email='[email protected]', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id, 
        TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
        insert u;
         u.IsPortalEnabled = true;
         u.ContactId=cons[0].id;
         update u;

        //return u;
     //Insert the test user
   Financial_Statment__c FinancialStatmenttest= new Financial_Statment__c(Business_Company_Name__c=accts[0].id);
    insert FinancialStatmenttest;

     System.runAs(u) {
         DisplaySuppliersDetailsForm controller = new DisplaySuppliersDetailsForm ();
         //System.assertEquals(c !=NULL);

     }     
}
}

I am using the above code for creating the account associated contacts as well as a portal user . I am getting the error as contact can be associated with only portal user. Please help on this topic how can I enable the created contact as portal user / the user which is getting created can have contact assigned to it.

1 Answer 1

4

The error is self explanatory. You can associate a Contact to a Portal User only. A Portal User will not have the System Administrator profile.

So replace this query

Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];

with

Profile p = [SELECT Id FROM Profile WHERE Name='Portal Profile'];

where Portal Profile is any Portal Profile associated with your Portal User.

Hope is helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .