ran67, to create Person Account you need specify the field LastName instead of Name field. "When a person account is created (or an existing business account is changed to a person account), a corresponding contact record is also created." (Salesforce)
public Opportunity[] opp ; public MyChecklist__c[] chklist{get;set;} public MyChecklist__c[] chklistapprove{get;set;} public MyChecklist__c[] chklistrefuse{get;set;} public MyChecklist__c[] chkrefused{get;set;} Set<Id> oppid = new Set<Id>(); Public Contact Con {get; set;} Public Account Ac {get; set;}
public user u{get;set;} public MyChecklist_All() {
u = [Select id,name ,LastName,FirstName,ContactId,Profile.Name from user where id=:UserInfo.getUserId()]; Con=[select id,lastname from Contact where id =: u.ContactId]; Ac = [select id,lastname from Account where PersonContactId =: con.Id]; opp=[select id from Opportunity where Accountid=:ac.id]; for(Opportunity aa: opp) { oppid.add(aa.id); } chklist=[select id,Name,Product_Checklist__r.name,Approved_On__c,Received__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid and Active__c=true]; chklistapprove=[select id,Name,Product_Checklist__r.name,Approved_On__c,Received__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid and Approval_Status__c='Accepted']; chklistrefuse=[select id,Name,Product_Checklist__r.name,Received__c,Approved_On__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid and Approval_Status__c != 'Refused' and Approval_Status__c != 'Accepted']; chkrefused=[select id,Name,Product_Checklist__r.name,Received__c,Approved_On__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid and Approval_Status__c = 'Refused']; } }
please help me to cover the code ...........thanks in advance
"Con=[select id,lastname from Contact where id =: u.ContactId];" In this case you need create new user and set ContactId field. And see please System.runAsmethod using
I have been created the new user . but still am not able to cover the code.........
I am send my testcase
@istest private class MyChecklist_All_Tc { static testMethod void validatetest1() {
Profile p = [select id from profile where name='Customer Portal Manager Custom']; User u = new User(alias = 'standt', email='standarduser@testorg.com', emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US', localesidkey='en_US', profileid = p.Id, timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com'); System.runAs(u) { Account a = new Account(); a.Name = 'Test Account'; a.BillingState = 'AL'; insert a;
Contact c = new Contact(); c.FirstName = 'Test'; c.LastName = 'Contact'; c.accountid=a.id; c.Email = 'contactemail@example.com'; insert c;
opportunity o = new opportunity(); o.name='test'; o.StageName='prospecting'; o.CloseDate=date.valueof('2011-10-05'); o.Accountid=a.id; insert o;
"In this case you need create new user and set ContactId field" for new user.
Try this:
All Answers
Set the field IsPersonAccount to True
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_account.htm
Hi.
InternalServerError, IsPersonAccount field is Read only.
ran67, to create Person Account you need specify the field LastName instead of Name field.
"When a person account is created (or an existing business account is changed to a person account), a corresponding contact record is also created." (Salesforce)
hi still am not able to cover the code .......
when am intializing the lastname also
............please hellp me to cover the code
i am sending my controller
controller:
public class MyChecklist_All
{
public Opportunity[] opp ;
public MyChecklist__c[] chklist{get;set;}
public MyChecklist__c[] chklistapprove{get;set;}
public MyChecklist__c[] chklistrefuse{get;set;}
public MyChecklist__c[] chkrefused{get;set;}
Set<Id> oppid = new Set<Id>();
Public Contact Con {get; set;}
Public Account Ac {get; set;}
public user u{get;set;}
public MyChecklist_All()
{
u = [Select id,name ,LastName,FirstName,ContactId,Profile.Name from user where id=:UserInfo.getUserId()];
Con=[select id,lastname from Contact where id =: u.ContactId];
Ac = [select id,lastname from Account where PersonContactId =: con.Id];
opp=[select id from Opportunity where Accountid=:ac.id];
for(Opportunity aa: opp)
{
oppid.add(aa.id);
}
chklist=[select id,Name,Product_Checklist__r.name,Approved_On__c,Received__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid
and Active__c=true];
chklistapprove=[select id,Name,Product_Checklist__r.name,Approved_On__c,Received__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid
and Approval_Status__c='Accepted'];
chklistrefuse=[select id,Name,Product_Checklist__r.name,Received__c,Approved_On__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid
and Approval_Status__c != 'Refused' and Approval_Status__c != 'Accepted'];
chkrefused=[select id,Name,Product_Checklist__r.name,Received__c,Approved_On__c,Received_On__c,Specification__c,Received_Document_Remarks__c,Approval_Status__c,Status1__c from MyChecklist__c where Opportunity_Name__c IN: oppid
and Approval_Status__c = 'Refused'];
}
}
please help me to cover the code ...........thanks in advance
"Con=[select id,lastname from Contact where id =: u.ContactId];"
In this case you need create new user and set ContactId field. And see please System.runAs method using
hi
I have been created the new user . but still am not able to cover the code.........
I am send my testcase
@istest
private class MyChecklist_All_Tc
{
static testMethod void validatetest1()
{
Profile p = [select id from profile where name='Customer Portal Manager Custom'];
User u = new User(alias = 'standt', email='standarduser@testorg.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');
System.runAs(u) {
Account a = new Account();
a.Name = 'Test Account';
a.BillingState = 'AL';
insert a;
Contact c = new Contact();
c.FirstName = 'Test';
c.LastName = 'Contact';
c.accountid=a.id;
c.Email = 'contactemail@example.com';
insert c;
opportunity o = new opportunity();
o.name='test';
o.StageName='prospecting';
o.CloseDate=date.valueof('2011-10-05');
o.Accountid=a.id;
insert o;
MyChecklist__c m1=new MyChecklist__c();
m1.name='Test';
m1.Opportunity_Name__c=o.id;
insert m1;
MyChecklist_All s1= new MyChecklist_All();
}
}
}
"In this case you need create new user and set ContactId field" for new user.
Try this: