• Guru Vemuru 11
  • NEWBIE
  • 30 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Hello All,

I need help in splitting FirstName and LastName in Account.

My Requirement:
If FirstName is empty, break LastName by first space character and use first part of it as firstname and the remaining as lastname.

How can I achieve this ? Trigger or Config.

Kindly Suggest.

Thanks.
Hello , i need help in test class of this visualforce page and controller, 

<apex:page controller="addJobCntrl"  sidebar="false" showHeader="false" >
<style>
.picklist{
 border:none;
 background-color : #ECECEC;
  width: 100%;
  padding: 12px 20px;

}
.picklist2{
 border:none;
 background-color : #ECECEC;
  width: 100%;
  padding: 12px 20px;

}

.lbl{
text-align:left;
font-family:Arial;
font-size:15px;
font-weight:bold;


}
.inp1 {
     border:none;
     background-color : #ECECEC;
     padding: 12px  30px;
     font-family:Arial;


  
}
.btn{

background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 8px 20px;
    text-align: center;
    text-decoration: none ;
    display: inline-block;
    font-size: 16px;



}

</style>
<apex:form >
<div align="center">
<apex:outputLabel value="Please choose Customer from below list and Click Create Job Button" styleClass="lbl" ></apex:outputLabel>
<br/>
<br/>
<apex:inputField value="{!jobIns.Customer__c}" label="" id="Customer"/>
<br/>
<apex:commandButton action="{!creatContract}"  value="Create Job" styleClass="btn"/>  
</div>
</apex:form>  
  
  
</apex:page>

This is its Controller 

public class addJobCntrl {

Public string leadID{get;set;}
Public Lead leadIns{get;set;}
Public Job__c jobIns{get;set;}


public addJobCntrl (){

leadID = apexpages.currentpage().getparameters().get('id');
leadIns= [select id, Company, State__c, Street__c , Zip__c , City__c , Type_of_Service_Proposal__c , Name  , Sales_Person__c, Insurance_Amount__c , Email, Credit_Application_received__c, Credit_Limit_Amount__c,  Phone from Lead where ID =: leadID ];
jobIns = new Job__c(Lead__c  = leadID );


}


Public PageReference creatContract(){


jobIns.Name = leadIns.Company;
jobIns.Sales_Rep__c = leadIns.Sales_Person__c;
jobIns.Billing_Contact__c = leadIns.Name  ;
jobIns.Billing_Email__c = leadIns.Email;
jobIns.Billing_Phone_Number__c =  leadIns.Phone;
jobIns.Street__c = leadIns.Street__c ;
jobIns.State__c = leadIns.State__c ;
jobIns.Zipcode__c = leadIns.Zip__c ;
jobIns.City__c = leadIns.City__c ;
jobIns.Service_Type__c = leadIns.Type_of_Service_Proposal__c ;
jobIns.Credit_Application_received__c = leadIns.Credit_Application_received__c;
jobIns.Credit_Amount_Limit__c = leadIns.Credit_Limit_Amount__c;
jobIns.Insurance_Amount__c = leadIns.Insurance_Amount__c;

upsert jobIns;



PageReference p = new PageReference('/' + this.jobIns.Id );
return p;
}
}


and this is its test class 

@isTest 
public class addJobCntrlTest{

static testMethod void testMethod1() {
       Account custIns = new Account();
       custIns.Name = 'test';
       custIns.QB_Company__c = 'qfs';
       custIns.QB_Account__c = 'test'; 
       custIns.Service_Type__c  = 'Mid-Construction';
       insert custIns;
       
       Job__c jobIns = new Job__c();
       jobIns.Name = 'test';
       jobIns.Sales_Rep__c = 'Aharon Kaplan';
       jobIns.Customer__c = custIns.ID;
       jobIns.Billing_Contact__c = 'test';  
       jobIns.Billing_Email__c= 'test@test.com'; 
       jobIns.Billing_Phone_Number__c= '123'; 
       jobIns.QB_Job_Name__c = 'test';   
       jobIns.QB_Company__c = 'QFS';
       
       insert jobIns;
       
       
        
       Lead testRecord= new Lead();
       testRecord.LastName = 'test name ';
       testRecord.Company = 'test company';
       testRecord.Status = 'new';
       testRecord.Credit_Limit_Amount__c = 12344;
       insert testRecord;
     

        Test.setCurrentPage(Page.addJob);
        System.currentPageReference().getParameters().put('id', testRecord.Id);

        addJobCntrl addjobCntrlTestIns = new addJobCntrl();
        
        addjobCntrlTestIns.creatContract();
    }
 }

this test class is giving this error. 

System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Customer__c]: [Customer__c]

I am not sure why i keep getting this error, i am getting customer__c value from visualforce page's input field from user, visualforce page is giving / creating correct records, but in test class it says customer__c value is required , 

can any one pleaes help me in this at your earliest possible ???? 
list<Opportunity> oppList = SATestUtil.createOpportunity(10);
        
        for(Opportunity opp : oppList ){
           opp.Type = 'New';
           opp.StageName = 'Executed'; 
           opp.Tenant_Construction = date.today();
           opp.Source_System_Id__c = 'test';
        }
    	update oppList;

 I am migrating records and I've wrote a batch class.In my query I have a where condition to filter the migrated records. how can i test for that in my test class?   the where condition is Source_System_Id__c != null;  I get an error System.DmlException: Update failed. First exception on row 1 with id 0061k000005ySO5AAM; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
  • March 21, 2019
  • Like
  • 0
I am getting following errors in below code

Field is not writeable: AccountShare.AccountAccessLevel
 Field is not writeable: AccountShare.CaseAccessLevel
 Field is not writeable: AccountShare.OpportunityAccessLevel
 Field is not writeable: AccountShare.AccountId
 Field is not writeable: AccountShare.UserOrGroupId



if(z==0 && resgroup.get(asset.Reseller__c)!=null){
                    Accountshare ashare = new AccountShare();
                    ashare.AccountAccessLevel='Edit';
                    ashare.CaseAccessLevel='None';
                    ashare.OpportunityAccessLevel='None';
                    ashare.AccountId=asset.AccountId;
                    ashare.userOrGroupId=resgroup.get(asset.Reseller__c);
                    newshares.add(ashare);
                }
Hello All,

I need help in splitting FirstName and LastName in Account.

My Requirement:
If FirstName is empty, break LastName by first space character and use first part of it as firstname and the remaining as lastname.

How can I achieve this ? Trigger or Config.

Kindly Suggest.

Thanks.