• Manjunath reddy 25
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 31
    Replies
<apex:page controller="costController"  action="{!updateitems}" showHeader="false" id="pageId">
<apex:stylesheet value="{!URLFOR($Resource.Apttus_Config2__ngCPQ, '/aptCPQUI/assets/stylesheets/angular-material.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.Apttus_Config2__vendor, '/lib/apttus-nova-design-system/lib/nova.min.css')}"/>
<apex:stylesheet value="{!URLFOR($Resource.Apttus_Config2__ngCPQ, '/aptCPQUI/assets/stylesheets/nova-design-style-changes.css')}"/>

  

<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script>
<script>
 var App = angular.module('myApp', []);
 App.controller('myctrl', function ($scope) { 
 $scope.lineItems= {!UpdateString};
 console.log("firstPrint $scope.lineItems===", $scope.lineItems);      
 $scope.items= [];
 
 //console.log("jsonlitem"+jsonlitem); 
 console.log("===========secondPrint $scope.lineItems===", $scope.lineItems); 
// $scope.json=angular.toJson($scope.lineItems); 
 
  $scope.getItems = function() {
      //alert($scope.lineItems);
      console.log("getitems -- Print $scope.lineItems", $scope.lineItems); 
        //console.log("jsonlitem"+jsonlitem);  
      var currentMinute = new Date().getMinutes();
      $scope.CurrentDate = new Date();
      alert('Save'+$scope.CurrentDate);
        $scope.json=angular.toJson($scope.lineItems); 
     Visualforce.remoting.Manager.invokeAction(
     '{!$RemoteAction.costController.ItemsUpdate}', 
     $scope.json,
     function(result, event) {
         //alert(result);
         //alert('enterFunction');
       $scope.items= result;
     }); 
  }
  
      $scope.reloadPage = function(){
      	$window.location.reload();
  	  }
      
 });
</script>

<style>
.button{
border: none;
border-radius: 5px;
background: #A5E0BB;
margin: .4rem .25rem;
font-size: .95rem;
padding: .4rem 1rem;
font-weight: 400;
border: none;
border-radius: 5px;
cursor: pointer;
color: #28492C;
margin-left: 500px;

}
</style>
<style>

table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.input{
padding: -20px;
text-align: left;
font-size: 15px;   
color: #2093DA;


}

.cost{
padding: -20px;
text-align: right;
font-size: 15px;   


}



th {
background-color: white;
color: #44596C;
min-width: 6rem;
text-align: center !important;
margin-bottom: .5rem;
font-size: 0.875rem;
line-height: 1rem;
font-weight: 700;
}
</style>
</head>
<body ng-app="myApp" class="container" > 

<div style="display:{!if(outPut,"block","none")};" ng-controller="myctrl">   

<table class="table table-bordered" id="t01" width="80%">
<tr>
    <th >Item </th>
    <th colspan="2" >Engineering </th>
    <th colspan="2">Sourcing</th>
    <th colspan="2">Manufacturing </th>
    <th colspan="2">I and FS </th>
    <th> </th>
    
</tr>
 <tr>
   <th></th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Cost/unit</th>
 </tr>
 

 <tr ng-repeat="linitem in lineItems| filter:query"> 
     <td>{{linitem.Apttus_Config2__OptionId__r.Name}}</td>
     <td>{{linitem.Apts_Engineering_per_item__c}}</td>
     <td>{{linitem.Apts_Engineering_per_project__c}}</td>
     <td>{{linitem.Apts_Sourcing_price_item__c}}</td>
     <td>{{linitem.Apts_sourcing_per_project__c }}</td>
     <td>{{linitem.apts_Manufacturing_per_item__c}}</td>
     <td>{{linitem.Apts_Manufacturing_per_project__c}}</td>
     <td>{{linitem.Apts_I_FS_per_item__c}}</td>
     <td>{{linitem.Apts_I_FS_per_project__c}}</td>
     <td>{{linitem.Cost_per_unit__c}}</td>
 </tr>
</table>    

</div>


<div style="display:{!if(edit,"block","none")};" ng-controller="myctrl">      
   <apex:form id="editForm">  
       {!now()}
    <table class="table table-bordered" id="t01" width="70%">
 <tr>
     <tr>
    <th width="40%">Item </th>
    <th colspan="2" >Engineering </th>
    <th colspan="2">Sourcing</th>
    <th colspan="2">Manufacturing </th>
    <th colspan="2">I and FS </th>
    <th> </th>
 </tr> 
</tr>
 <tr>
   <th width="100%"></th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Per Item</th>
   <th>Per Project</th>
   <th>Cost/unit</th>
 </tr>
 
 <tr ng-repeat="linitem in lineItems| filter:query">     
     <td >
     <div ng-if="linitem.Apttus_Config2__OptionId__r.Name == null " style="color:#2093DA;font-weight:bold" > 
        {{linitem.Bundle_Name__c}} 
    </div>
    
     <div ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "  class="input">  
        {{linitem.Apttus_Config2__OptionId__r.Name}} 
    </div>
     </td>
     <td><input type="text" ng-model=" linitem.Apts_Engineering_per_item__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td><input type="text" ng-model=" linitem.Apts_Engineering_per_project__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td><input type="text" ng-model=" linitem.Apts_Sourcing_price_item__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td><input type="text" ng-model=" linitem.Apts_sourcing_per_project__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td><input type="text" ng-model=" linitem.apts_Manufacturing_per_item__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td><input type="text" ng-model=" linitem.Apts_Manufacturing_per_project__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td><input type="text" ng-model=" linitem.Apts_I_FS_per_item__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td><input type="text" ng-model=" linitem.Apts_I_FS_per_project__c" style="width:80px;" ng-if="linitem.Apttus_Config2__OptionId__r.Name != null "/></td>
     <td ng-if="linitem.Apttus_Config2__OptionId__r.Name != null" class="cost">{{linitem.Cost_per_unit__c}}</td>         
 </tr> 
</table>
        <apex:actionFunction name="jsCallMethod"   reRender="pageId"/>
    		
            <apex:outputPanel onclick="jsCallMethod()">
                <button  ng-click="getItems()" class="button" >Save </button>
            </apex:outputPanel>
       </apex:form>    
        
        
</div>


      

</body>

</apex:page>

When page refreshed manually we can see the values changed in the table, but when  page rerendered using actionfunction in the code when clicked on save, values are not changed.
Hi All,
I need help on the issue with my VF page, My VF page code and my controller code is as below.in the below code in y controller, I have created a boolean variable called dupRecord,which I made true in the catch block, I am trying to access dupRecord variable in the method in the closingTheTab method., as per debug logs, I am able to get dupRecord is true in the catch block, but Iam not able to get dupRecord variable as true in closingTheTab method, Iam trying to send dupRecord variable from apex;:param to duprecord2, but I am not gettting expected result, before that, I just made the dupRecord as true in catch block and tried accessin in the closingTheTab , but not able to get expected result, please help me on this.
<apex:page standardController="HPE_Account_Team__c" extensions="GSDAccountteammembercontroller" sidebar="false" showHeader="false">
<apex:pagemessages id="EMSG"/>
<apex:includeScript value="/support/console/33.0/integration.js"/>
<script type="text/javascript">
    
        function RefreshPrimaryTab() 
        {
            //var primaryTabId = 'navigatortab__scc-pt-1';
            sforce.console.getFocusedPrimaryTabId(showTabId);
        }
            
        var showTabId = function showTabId(result) 
        {
            var tabId = result.id;
            sforce.console.refreshPrimaryTabById(tabId , true, refreshSuccess);
        };
        
        var refreshSuccess = function refreshSuccess(result) 
        {
            //Report whether refreshing the primary tab was successful
            if (result.success == true) 
            {
                alert('Primary tab refreshed successfully');
            } 
            else 
            {
                alert('Primary did not refresh');
            }
        };          


function ClosetheTab() {        
    if(sforce.console.isInConsole()) {
        sforce.console.getEnclosingTabId(closeSubtab);
        //var primaryTabId = 'navigatortab__scc-pt-1';
        sforce.console.getFocusedPrimaryTabId(showTabId);
        }
        else{
        alert('hello it is out of console');
        //window.location.href = location.protocol + '//' + window.location.hostname + '/' + '{!parentrecordid}';
        //window.location.href = window.opener.location.href;
        window.opener.refreshoutofconsole();
        alert('hello it is out of console2');
        window.top.close();

        }
    } 
    var closeSubtab = function closeSubtab(result) {

        //Now that we have the tab ID, we can close it
        var tabId = result.id;
        sforce.console.closeTab(tabId);
    };

function CloseSavePage(TabToBeClosed){
    alert('Now it is reached to CloseSavePage function');
    alert(TabToBeClosed);
    //TabToBeClosed=true;
    //alert(TabToBeClosed);
    if(TabToBeClosed==='true'){
        ClosetheTab();
    }
    alert('Now it is reached to ClosetheTab function');
}

function CloseTaboncancel() {        
    if(sforce.console.isInConsole()) {
          sforce.console.getEnclosingTabId(closeSubtab);
        }
        else{
        window.top.close();
    }
}
</script>
    <apex:form >
        <apex:actionFunction name="priorityChangedJavaScript"   action="{!closingtheTab}" oncomplete="CloseSavePage('{!TabToBeClosed}');return false"/ > 
                    <apex:pageblock >            
            <apex:pageBlockTable value="{!listofrecords}" var="Acc" id="pbt">
            <apex:column headerValue="Name" style="width:250px">
                <apex:inputField value="{!Acc.Name__c}" required="false" />
            </apex:column>
            <apex:column headerValue="Role">
                <apex:inputField value="{!Acc.Role__c}" required="false"/>
            </apex:column>
            <apex:column headerValue="Role Scope">
                <apex:inputField value="{!Acc.Role_Scope__c}" required="false"/>
            </apex:column>
            <apex:column headerValue="Role Scope Description">
                <apex:inputField value="{!Acc.Role_Scope_Description__c}" style="width:600px"/>
            </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
            
            <apex:commandButton action="{!SaveRecords}" value="Save" reRender="Pbt,EMSG"  onclick="priorityChangedJavaScript()">
                {!dupRecord};
            {!dupRecord2};
                <apex:param value="{!dupRecord}" assignTo="{!dupRecord2}"/>
                {!dupRecord};
            {!dupRecord2};
             </apex:commandButton>
            
                <apex:commandButton value="Cancel" onclick="CloseTaboncancel()"/>
            </apex:pageBlockButtons>
        </apex:pageblock>
    </apex:form>
</apex:page>
 
public  class GSDAccountteammembercontroller {
    public list<HPE_Account_Team__c> listofrecords{get;set;}
    public Boolean TabToBeClosed {get;set;}
    public string parentrecordid{get;set;}
    public HPE_Account_Team__c HPEAccountTeam{get;set;} 
    public string recieveID{get;set;}
    public string currentAccountPageId{get;set;}
    public boolean dupRecord{get;set;}
    public boolean dupRecord2{get;set;}
    
    
    //Constructor
    public GSDAccountteammembercontroller(ApexPages.StandardController controller){
        //tabTobeClosed = true;
        dupRecord=false;
        dupRecord2=false;
        parentrecordid = ApexPages.currentPage().getParameters().get('Account__c');//this line is for when the record is coming from the ASDP page
        recieveID= ApexPages.currentPage().getParameters().get('sendasdpid');
        system.debug('recieveID'+recieveID);
        system.debug('parentrecordid'+parentrecordid);
        HPEAccountTeam=(HPE_Account_Team__c)controller.getrecord();
        system.debug('HPEAccountTeam.id'+HPEAccountTeam.id);
        if(HPEAccountTeam.account__c!=null){
            recieveID=HPEAccountTeam.account__c;
        }
        system.debug('HPEAccountTeam'+HPEAccountTeam);
        currentAccountPageId= ApexPages.currentPage().getParameters().get('id');
        system.debug('currentAccountPageId'+currentAccountPageId);
        if(parentrecordid == null || parentrecordid == ''){
        system.debug('Enter parentrecordid '+parentrecordid );
                parentrecordid = HPEAccountTeam.Account__c;
                system.debug('Enter parentrecordid '+parentrecordid );
        }
              
        HPE_Account_Team__c accteam;
        //tabToBeClosed = false;
        listofrecords = new list<HPE_Account_Team__c>();
            for(Integer i=accountConstants.Zero; i<accountConstants.Five ; i++){   
                accteam = new HPE_Account_Team__c();       
                listofrecords.add(accteam);
             }
     } 
      
      
    //Save method 
    public PageReference SaveRecords() {
        list<HPE_Account_Team__c> AccountTeamtoBeInserted= new list<HPE_Account_Team__c>(); 
        try{
         //tabToBeClosed = true;
          system.debug('Save parentrecordid '+parentrecordid );
          
            for(HPE_Account_Team__c acctem :listofrecords){
                acctem.Account__c = parentrecordid;
                if(acctem.Name__c!= null && acctem.Role__c!=null && acctem.Role_Scope__c!=null ){
                    AccountTeamtoBeInserted.add(acctem);
                }
                else if(acctem.Name__c != null || acctem.Role__c!=null || acctem.Role_Scope__c!=null ){
                   ApexPages.Message errorMessage= new ApexPages.Message(ApexPages.Severity.ERROR, Label.GSD_Account_Error_Message);ApexPages.addMessage(errorMessage);
                   return null; 
                }
             }
                if(AccountTeamtoBeInserted.size() > 0)
                    insert AccountTeamtoBeInserted;
                else{
                    ApexPages.Message errorMessage= new ApexPages.Message(ApexPages.Severity.ERROR, Label.GSD_Account_Error_Message);ApexPages.addMessage(errorMessage);
                    //tabTobeClosed = false;
                    return null; 
                }
        }
        catch(Exception ex){           
             ApexPages.addMessages(ex);
             //tabTobeClosed = false;
             dupRecord= true;
             system.debug('dupRecord' +dupRecord);
             return null;
         }    
            
        string BaseURL = URL.getSalesforceBaseUrl().toExternalForm();
        system.debug('recieveID'+recieveID); 
             PageReference redirectTopage = new PageReference(BaseURL+'/'+recieveID);
             redirectTopage.setRedirect(true);
             return redirectTopage;
    }
    
    public void closingtheTab(){
        system.debug('The value is before making true' +tabToBeClosed);  
        system.debug('dupRecord2' +dupRecord);  
         for(HPE_Account_Team__c acctem :listofrecords){
                if(acctem.Name__c!= null && acctem.Role__c!=null && acctem.Role_Scope__c!=null ){
                    system.debug('tabToBeClosed' +tabToBeClosed);
                    tabToBeClosed = true;
                    system.debug('tabToBeClosed' +tabToBeClosed);
                    system.debug('dupRecord' +dupRecord);
                    if(dupRecord2==true){
                        tabToBeClosed = false;
                    }
                    break;
                } 
                else if(acctem.Name__c == null || acctem.Role__c == null || acctem.Role_Scope__c == null ){
                    system.debug('tabToBeClosed' +tabToBeClosed);
                    tabToBeClosed = false;
                }
         }
        system.debug('The value is after making true' +tabToBeClosed);
        
    }

}


 
I have written a validation rule  as below,

AND( 
$Setup.Global_Config__c.Mute_Validation_Rule__c <> TRUE, 
OR( 
ISBLANK( Account__c ), 
ISBLANK( Name__c ), 
ISPICKVAL( Role__c , ''), 
ISPICKVAL( Role_Scope__c , ''), 
AND( 
ISPICKVAL( Role__c , "Other"), 
LEN(Role_Scope_Description__c) = 0 


)

but when I click save butonn with empty fields , it is not throwing an error, If we select two or mor fileds it i throwing an error,can some one help me on this.
I want to display a custom error message if my workflow rule fires and fails. Basically, I am trying to avoid duplicate dates. I have got my workflow running, but right now it displays the following message:
"duplicate value found: Unique_Key__c duplicates value on record with id: a04j0000002bTQs"

To achieve that,I am using the below ateps and code.

1) Write controller and override the Save method
2) In save method use try cache block and show whatever message I want to show
try{
    update myObj;
}
catch(Exception exc)
{
    if(exc.getMessage().contains('FIELD_FILTER_VALIDATION_EXCEPTION'))
    {
        Trigger.new[0].addError('Please select only active entities.');
    }
}
still I am not getting custom message.

My controller is as below
/**
* @author : HP 
* @date 30/08/2016 
* @description : GSDAccountteammembercontroller class is used to insert the records into 'HPE_Account_Team__c' object.
* $client$ [gsd|spt|common]: gsd 
//Class Header Starts
//Class Name:[GSDAccountteammembercontroller]
---------------------------------------------------------------------------------------------------------------------------------
//        DateTime[UTC]      |  Email_id                        |Stream     |   Release         |     Description
---------------------------------------------------------------------------------------------------------------------------------
//        30/08/2016[04:30]  |~:saran-kumar-satya.b-v@hpe.om    | CSC | GSDR9-SFDC      |   GSDAccountteammembercontroller class is used to insert the records into 'HPE_Account_Team__c' object
//Class Header Ends

**/

public  class GSDAccountteammembercontroller {


public list<HPE_Account_Team__c> listofrecords{get;set;}
public Boolean TabToBeClosed {get;set;}
    
public PageReference SaveRecords() 
{
    string parentrecordid = ApexPages.currentPage().getParameters().get('Account__c');
    list<HPE_Account_Team__c> insertlist = new list<HPE_Account_Team__c>();  
    for(HPE_Account_Team__c acctem :listofrecords)
    {
        system.debug('acctem.Name__c'+acctem.Name__c);
        system.debug('parentrecordid'+parentrecordid);
        system.debug('listofrecords'+listofrecords);
        if(acctem.Name__c!=null)
        {
          if(parentrecordid != null && parentrecordid != '')
          acctem.Account__c = parentrecordid ;
          insertlist.add(acctem);
        
        }              
       
    }
        try{
        insert insertlist;
        }
        catch(Exception ex){
         
         if(ex.getMessage().contains('FIELD_FILTER_VALIDATION_EXCEPTION')) {
             Trigger.new[0].addError('Please select only active entities.');
         }
         ApexPages.addMessages(ex);
         return null;
        }       
        if(listofrecords!=null){
        listofrecords.clear();
        }
        TabToBeClosed = true;
        return null;

}

public GSDAccountteammembercontroller(ApexPages.StandardController controller){
 HPE_Account_Team__c HPEAccountTeam=(HPE_Account_Team__c)controller.getrecord();
 system.debug('HPEAccountTeam'+HPEAccountTeam);
TabToBeClosed = false;

listofrecords = new list<HPE_Account_Team__c>();
    
    for(Integer i=0; i<5; i++){   
         HPE_Account_Team__c gsdaccteam = new HPE_Account_Team__c();
         gsdaccteam.Account__c=HPEAccountTeam.Account__c;        
         gsdaccteam.Name__c=null;
         gsdaccteam.Role_Scope_Description__c='';
         gsdaccteam.Role__c='';
                 
         listofrecords.add(gsdaccteam);
    
         }
         
        
     
} 
  
}

 
HI I need help in improving the code coverage for the below class.
public  class GSDAccountteammembercontroller {


public list<HPE_Account_Team__c> listofrecords{get;set;}
public Boolean TabToBeClosed {get;set;}
    
public PageReference SaveRecords() 
{
    string parentrecordid = ApexPages.currentPage().getParameters().get('Account__c');
    list<HPE_Account_Team__c> insertlist = new list<HPE_Account_Team__c>();  
    for(HPE_Account_Team__c acctem :listofrecords)
    {
        system.debug('acctem.Name__c'+acctem.Name__c);
        system.debug('parentrecordid'+parentrecordid);
        system.debug('listofrecords'+listofrecords);
        if(acctem.Name__c!=null)
        {
          if(parentrecordid != null && parentrecordid != '')
          acctem.Account__c = parentrecordid ;
          insertlist.add(acctem);
        
        }              
       
    }
        try{
        insert insertlist;
        }
        catch(Exception ex){
         ApexPages.addMessages(ex);
         return null;
        }       
        if(listofrecords!=null){
        listofrecords.clear();
        }
        TabToBeClosed = true;
        return null;

}

public GSDAccountteammembercontroller(ApexPages.StandardController controller){
 HPE_Account_Team__c HPEAccountTeam=(HPE_Account_Team__c)controller.getrecord();
 system.debug('HPEAccountTeam'+HPEAccountTeam);
TabToBeClosed = false;

listofrecords = new list<HPE_Account_Team__c>();
    
    for(Integer i=0; i<5; i++){   
         HPE_Account_Team__c gsdaccteam = new HPE_Account_Team__c();
         gsdaccteam.Account__c=HPEAccountTeam.Account__c;        
         gsdaccteam.Name__c=null;
         gsdaccteam.Role_Scope_Description__c='';
         gsdaccteam.Role__c='';
                 
         listofrecords.add(gsdaccteam);
    
         }
     
} 
  
}

My test class is as below.I am not able to cover the code few lines of the main class, thos lines area as below, find the attachement of screenshot.Screen shot taken from developer console.

 if(acctem.Name__c!=null)
        {
          if(parentrecordid != null && parentrecordid != '')
          acctem.Account__c = parentrecordid ;
          insertlist.add(acctem);
        
        }   
@isTest
public class GSDAccountteammembercontrollerTest{
    private static testMethod void SaveRecordTest(){
        account acc = new account();
        acc.name='test';
        insert acc;
        
        contact con = new contact();
            con.email = 'test@yahoo.com';
            con.Phone__c = '5423515415';
            con.LastName ='last Name';  
        insert con;
        system.debug('con'+con);
        
        HPE_Account_Team__c hpeAccountTeam = new HPE_Account_Team__c();
            hpeAccountTeam.Account__c = acc.id;
            hpeAccountTeam.Name__c = con.id;
            hpeAccountTeam.Role__c = 'Other';
            hpeAccountTeam.Role_Scope__c = 'Global';
            hpeAccountTeam.Role_Scope_Description__c = 'testing';
            hpeAccountTeam.Unique_Key__c = 'dfaafs';
            
            insert hpeAccountTeam;
    
  
        user u = [select id from user where id=:userInfo.getUserId()];
        
        System.runAs(u){
            ApexPages.StandardController con1 = new ApexPages.StandardController(hpeAccountTeam);
            GSDAccountteammembercontroller  teamMemberController = new GSDAccountteammembercontroller(con1);
            teamMemberController.SaveRecords();   
                

        }              
    }
}
Need help in writing test class for the below class


public  class GSDAccountteammembercontroller {

public list<HPE_Account_Team__c> listofrecords{get;set;}
public Boolean displayBOMPopUp {get;set;}
public Boolean TabToBeClosed {get;set;}
    
public PageReference SaveRecords() 
{
system.debug('Method Entry');
    //Id parentrecordid = ApexPages.currentPage().getParameters().get('Id');
    Id parentrecordid = '001G000001IgfGZ';
    list<HPE_Account_Team__c> insertlist = new list<HPE_Account_Team__c>();  
    system.debug('After the Method Entry');
    for(HPE_Account_Team__c acctem :listofrecords)
    {
        system.debug('Entered the for condition'+acctem.Account__c);
        if(acctem.Name__c!=null)
        {
            acctem.Account__c = parentrecordid;
            insertlist.add(acctem);
            system.debug('Method Entry'+insertlist);
        
        }               
       
    }
        try{
        insert insertlist;
        }
        catch(Exception ex){
         //ApexPages.addmessage(new Apexpages.Message(ApexPages.Severity.ERROR, ex.getMessage()));
         ApexPages.addMessages(ex);
         return null;
        }       
        if(listofrecords!=null){
        listofrecords.clear();
        }
        TabToBeClosed = true;
        return null;

}

public GSDAccountteammembercontroller(){
displayBOMPopUp = false;
TabToBeClosed = false;

listofrecords = new list<HPE_Account_Team__c>();
    
    for(Integer i=0; i<5; i++){   
         HPE_Account_Team__c gsdaccteam = new HPE_Account_Team__c();
         gsdaccteam.Account__c=null;
         List<PermissionSetAssignment> UserHasDCDMPerission = new List<PermissionSetAssignment>([SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'GSDAccountDCDMRole']);
         if(UserHasDCDMPerission.size() > 0)
          gsdaccteam.recordtypeid = Schema.SObjectType.HPE_Account_Team__c.getRecordTypeInfosByName().get('DCDM').getRecordTypeId();
        
         gsdaccteam.Name__c=null;
         gsdaccteam.Role_Scope_Description__c='';
         gsdaccteam.Role__c='';
                 
         listofrecords.add(gsdaccteam);
    
         }

     


public void TestActFun(){
    
displayBOMPopUp = true;
}

public void TestPopUp(){

displayBOMPopUp = true;
}

public void closeBOMPopUp() {
    
    displayBOMPopUp = false;

}  
}
How to write a test class for the below class
public with sharing class GSDASDPHPEAccountTeam {
    public GSD_Account_Success_Delivery_Plan__c mainAcctID;
    public GSDASDPHPEAccountTeam(ApexPages.StandardController std)
    {
        mainAcctID = [select id, Account__c, Related_To_Account_Business_Plan__c,Related_To_Account_Business_Plan__r.primary_accountaccount__c from GSD_Account_Success_Delivery_Plan__c where id = :std.getId()];
    }
   
    public list<HPE_Account_Team__c> getHPEAccountTeam(){
        return [select Name, Account__r.Name,Name__r.Name, Phone__c, Email__c, Role__c, Role_Scope__c, Role_Scope_Description__c from HPE_Account_Team__c where Account__c = : mainAcctID.Account__c];
    }
    
}

 
Hi I am trying to make a call out using rest services.the scenario is when I create an account in source org I should create an account in the target org.I have created a trigger SendAccount which calls the class SendAccountFromSource. Iam able to get access token as a response, but I am not able to get response when I use end point URL my debuglogs are given below, please anyone help me on this
trigger SendAccount on Account(after insert){
    for(Account a : Trigger.new){
            SendAccountFromSource.createAccount(a.Name, a.Id);        
     }
}
 
public class SendAccountFromSource {
    private final String clientId = '3MVG9Y6d_Btp4xp5pS0Mwb345aVwqNmCpRF9rEs1QMG_WkvGPZtIKsyUgujSZPhIcCzzxFQqugJCA7fs7SkZB';
    private final String clientSecret = '3594199692394096988';
    private final String username = 'manjunath@ceptes.com';
    private final String password = 'Surya@123SKIjxR3KtHFY6wv3uhLfbga0E';
public class deserializeResponse{
    public String id;
    public String access_token;
}
public String ReturnAccessToken (SendAccountFromSource acount){
    String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqbody);
system.debug('====================reqbody============'+reqbody);
req.setMethod('POST');
req.setEndpoint('https://ap1.salesforce.com/services/oauth2/token');
system.debug('====================req============'+req);
HttpResponse res = h.send(req);
system.debug('====================res============'+res);
    deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
system.debug('====================resp1============'+resp1);
system.debug('====================resp1.access_token============'+resp1.access_token);
String accessToken = resp1.access_token;
String accName = 'Shiva8';
return accessToken;
}
@future(callout=true)
public static void createAccount(String accName, String accId){
    system.debug('====================accId============'+accId);
    SendAccountFromSource acount = new SendAccountFromSource();
    system.debug('===acount == '+acount );
    String accessToken = acount.ReturnAccessToken (acount);
    if(accessToken != null){
    system.debug('====================accId============'+accId);
    String endPoint = 'https://ap1.salesforce.com/services/apexrest/createAccount/';
                       //https://ap1.salesforce.com/services/apexrest/v1/getaccountids/
    //String endPoint = 'https://ap1.salesforce.com/services/apexrest/v1/getaccountids/';
    //String jsonstr = '{"AccName" : "' + accName + '"}';
    String jsonstr = '{"Name" : "' + accName + '"}';
    
    Http h2 = new Http();
    HttpRequest req1 = new HttpRequest();
    req1.setHeader('Authorization','Bearer ' + accessToken); 
    req1.setHeader('Content-Type','application/json;charset=UTF-8');
    req1.setHeader('accept','application/json');
    req1.setBody('jsonstr');
    req1.setMethod('POST');
    req1.setEndpoint(endPoint);
    HttpResponse res1 = h2.send(req1);
       system.debug('====================res1============'+res1.getBody());
    String trimmedResponse = res1.getBody().unescapeCsv().remove('\\');
    system.debug('====================trimmedResponse ============'+trimmedResponse );
    deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(trimmedResponse, deserializeResponse.class);
    system.debug('====================resp2 ============'+resp2);

    
    
    Account a = [SELECT Id FROM Account WHERE Id = :accId];
    //a.externalId__c= resp2.id;
    update a; 

       
  } 
}
}
16:55:38.17 (17241361)|CODE_UNIT_STARTED|[EXTERNAL]|01p280000054SO5|SendAccountFromSource.createAccount 16:55:38.17 (18294404)|USER_DEBUG|[30]|DEBUG|====================accId============0012800000peYgoAAE 16:55:38.17 (18506002)|USER_DEBUG|[32]|DEBUG|===acount == SendAccountFromSource:[clientId=3MVG9Y6d_Btp4xp5pS0Mwb345aVwqNmCpRF9rEs1QMG_WkvGPZtIKsyUgujSZPhIcCzzxFQqugJCA7fs7SkZB, clientSecret=3594199692394096988, password=Surya@123SKIjxR3KtHFY6wv3uhLfbga0E, username=manjunath@ceptes.com] 16:55:38.17 (18681163)|USER_DEBUG|[15]|DEBUG|====================reqbody============grant_type=password&client_id=3MVG9Y6d_Btp4xp5pS0Mwb345aVwqNmCpRF9rEs1QMG_WkvGPZtIKsyUgujSZPhIcCzzxFQqugJCA7fs7SkZB&client_secret=3594199692394096988&username=manjunath@ceptes.com&password=Surya@123SKIjxR3KtHFY6wv3uhLfbga0E 16:55:38.17 (18780827)|USER_DEBUG|[18]|DEBUG|====================req============System.HttpRequest[Endpoint=https://ap1.salesforce.com/services/oauth2/token, Method=POST] 16:55:38.17 (18859108)|CALLOUT_REQUEST|[19]|System.HttpRequest[Endpoint=https://ap1.salesforce.com/services/oauth2/token, Method=POST] 16:55:38.17 (488682227)|CALLOUT_RESPONSE|[19]|System.HttpResponse[Status=OK, StatusCode=200] 16:55:38.17 (488841703)|USER_DEBUG|[20]|DEBUG|====================res============System.HttpResponse[Status=OK, StatusCode=200] 16:55:38.17 (489959480)|USER_DEBUG|[22]|DEBUG|====================resp1============deserializeResponse:[access_token=00D90000000gZ83!AQEAQKB7bYRQZObCuq7fvGfN8p9xc9UjvF2hvRmsc5xFc778E6IPDYfqeFCJxIAjet8vdhk8rzk2Rgnw5VngAWBcv.JypYsv, id=https://login.salesforce.com/id/00D90000000gZ83EAE/005900000014zatAAA] 16:55:38.17 (490013080)|USER_DEBUG|[23]|DEBUG|====================resp1.access_token============00D90000000gZ83!AQEAQKB7bYRQZObCuq7fvGfN8p9xc9UjvF2hvRmsc5xFc778E6IPDYfqeFCJxIAjet8vdhk8rzk2Rgnw5VngAWBcv.JypYsv 16:55:38.17 (490065182)|USER_DEBUG|[35]|DEBUG|====================accId============0012800000peYgoAAE 16:55:38.17 (492632717)|CALLOUT_REQUEST|[50]|System.HttpRequest[Endpoint=https://ap1.salesforce.com/services/apexrest/createAccount/, Method=POST] 16:55:38.17 (688726311)|CALLOUT_RESPONSE|[50]|System.HttpResponse[Status=Bad Request, StatusCode=400] 16:55:38.17 (688871235)|USER_DEBUG|[51]|DEBUG|====================res1============[{"message":"Unexpected character ('j' (code 106)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:2]","errorCode":"JSON_PARSER_ERROR"}] 16:55:38.17 (689407452)|USER_DEBUG|[53]|DEBUG|====================trimmedResponse ============[{"message":"Unexpected character ('j' (code 106)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:2]","errorCode":"JSON_PARSER_ERROR"}] 16:55:38.17 (689816529)|FATAL_ERROR|System.JSONException: Malformed JSON: Expected '{' at the beginning of object Class.System.JSON.deserialize: line 15, column 1 Class.SendAccountFromSource.createAccount: line 54, column 1 16:55:38.17 (689839357)|FATAL_ERROR|System.JSONException: Malformed JSON: Expected '{' at the beginning of object Class.System.JSON.deserialize: line 15, column 1 Class.SendAccountFromSource.createAccount: line 54, column 1
Hi,

I am getting error 
Error: Compile Error: No such column 'account' on entity 'Contract'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 6 column 67

but I am using standard fields which are available on contract object , my code is as below, can some one help me on this.
trigger updatePicklist on Contract (before insert, before update) {
    List<id> contractIds = new list<id>();
    for(contract c : trigger.new){
        contractIds.add(c.id);
    }
    map<account,contract> contractMap = new map<account,contract>([select account,Pricebook2 from contract where account in : contractIds]);
}

 
Hi both the below triggers wotks fine , I have a question here , in my first trigger posted below I am using DML update accs.values();,If I remove DML trigger doesn't work, in my second trigger If I use DML update contactListToUpdate;, iam getting error

 "Error: Apex trigger ownerChange caused an unexpected exception, contact your administrator: ownerChange: execution of BeforeUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id 0039000001yu7JUAAY; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, changeOwner: execution of AfterUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id 0019000001i0umdAAA; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0019000001i0umd) is currently in trigger ownerChange, therefore it cannot recursively update itself: []

(): []: ()"


Now Iam confused whether we can use DML operations in before triggers or not.Can some explain me if we can use DML operations in before triggers
trigger ownerChange on Account (before insert, before update) {
    List<id> accountIdsList = new list<id>();
    list<contact> contactListToUpdate = new list<contact>();
    for(account acc : trigger.new){
        accountIdsList.add(acc.id);
    }
    
    list<contact> contactList = [select id from contact where accountId IN:accountIdsList ];
    
    for(account acc : trigger.new){
        if(acc.ownerId!=trigger.oldMap.get(acc.id).ownerId){
         for(contact con : contactList){
             con.ownerId = acc.ownerId;
             contactListToUpdate.add(con);
         }    
        
        }
        update contactListToUpdate;
    }
    
    
}

?
/ The trigger needs to check all the other Opportunities related to the Account of the Opportunity being updated. It should check to see if any of the Opportunities have a StageName equal to 'Closed Won ',
// if so, it should update the account Type to 'Customer'. If none of the Opportunities are closed won, the Account Type should be 'Prospect
trigger updateAccountIfOppCustomer on Opportunity (before insert, before update) {
    list<opportunity> accOpps = new list<opportunity>();
    list<id>  accountIds = new list<id>();
    
    for(opportunity opp:trigger.new){
        accountIds.add(opp.accountId);
    }
    
    list<opportunity> opps = [select id,AccountId,StageName  from opportunity where accountId IN:accountIds];
    map<id,account> accs = new map<id,account>([select id,type from account where id IN:accountIds]);
    system.debug('accs '+accs );
    for(opportunity o:opps){
            if (o.StageName == 'Closed Won'  || o.StageName == 'Customer Reseller') {
                //acc.type = 'prospect';
                accs.get(o.accountId).type='prospect';
        }
    }
    
    update accs.values();
    
}

 
I'm currently trying to create a trigger that runs whenever an Opportunity is created or updated. The trigger needs to check all the other Opportunities related to the Account of the Opportunity being updated. It should check to see if any of the Opportunities have a StageName equal to 'Closed Won ', if so, it should update the account Type to 'Customer'. If none of the Opportunities are closed won, the Account Type should be 'Prospect'.but iam getting accs.get(o.accountId).type as null in debug log.can someone help me on this.
trigger updateAccountIfOppCustomer on Opportunity (before insert, before update) {
    list<opportunity> accOpps = new list<opportunity>();
    list<id>  accountIds = new list<id>();
    
    for(opportunity opp:trigger.new){
        accountIds.add(opp.accountId);
    }
    
    list<opportunity> opps = [select id,AccountId,StageName  from opportunity where accountId IN:accountIds];
    map<id,account> accs = new map<id,account>([select id,type from account where id IN:accountIds]);
    system.debug('accs '+accs );
    for(opportunity o:opps){
            if (o.StageName == 'Closed Won'  || o.StageName == 'Customer Reseller') {
                //acc.type = 'prospect';
                accs.get(o.accountId).type='prospect';
        }
    }
    
}

 
I am trying to update the field of the child object when the type field in case is changed, but iam getting empty child list
system.debug('c.Casechilds__r'+c.Casechilds__r);, can some one help me on this

debug logs is as follows
11:06:12.0 (3510151)|SOQL_EXECUTE_BEGIN|[8]|Aggregations:1|SELECT id, (SELECT id, Field_to_update__c FROM Casechilds__r) FROM case WHERE id IN :tmpVar1 11:06:12.0 (9078923)|SOQL_EXECUTE_END|[8]|Rows:1 11:06:12.0 (9255628)|USER_DEBUG|[9]|DEBUG|caseList(Case:{Id=5002800000O4w0fAAB}) 11:06:12.0 (9310150)|USER_DEBUG|[10]|DEBUG|caseIds (5002800000O4w0fAAB) 11:06:12.0 (10027977)|USER_DEBUG|[12]|DEBUG|cCase:{Id=5002800000O4w0fAAB, IsDeleted=false, CaseNumber=00001027, ContactId=null, AccountId=null, AssetId=null, BusinessHoursId=01m28000000DrvlAAC, ParentId=null, SuppliedName=null, SuppliedEmail=null, SuppliedPhone=null, SuppliedCompany=null, Type=Electrical, Status=New, Reason=null, Origin=Phone, Subject=null, Priority=Medium, Description=null, IsClosed=false, ClosedDate=null, IsEscalated=false, OwnerId=00528000002LYzBAAW, IsClosedOnCreate=false, CreatedDate=2016-08-09 05:34:43, CreatedById=00528000002LYzBAAW, LastModifiedDate=2016-08-09 05:36:12, LastModifiedById=00528000002LYzBAAW, SystemModstamp=2016-08-09 05:36:12, LastViewedDate=null, LastReferencedDate=null, EngineeringReqNumber__c=null, SLAViolation__c=null, Product__c=null, PotentialLiability__c=null} 11:06:12.0 (10168326)|USER_DEBUG|[13]|DEBUG|c.Casechilds__r() 11:06:12.10 (10443794)|CUMULATIVE_LIMIT_USAGE 11:06:12.10 (10443794)|LIMIT_USAGE_FOR_NS|(default)|
trigger updateChild on Case (after insert, after update){
    list<id> caseIds = new list<id>();
    list<id> childCaseIds = new list<id>();
    for(case c:trigger.new){
        caseIds.add(c.id);
    }
    
   list<case> caseList= [select id,(select id,Field_to_update__c from Casechilds__r)from case where id IN : caseIds ];
   system.debug('caseList'+caseList);
   system.debug('caseIds '+caseIds );
   for(case c : trigger.new){
       system.debug('c'+c);
       system.debug('c.Casechilds__r'+c.Casechilds__r);
       for(Case_child__c casechild :c.Casechilds__r){
           system.debug('casechild '+casechild );
           casechild.Field_to_update__c  = c.type;
           system.debug('casechild.Field_to_update__c'+casechild.Field_to_update__c);
           childCaseIds.add(casechild.id);
           system.debug('childCaseIds'+childCaseIds);
       }
      }
   // update childCaseIds;

}

 
trigger abcAccount on Opportunity (before update) {
    list<id> oppIds = new list<id>();
    //if(trigger.isInsert || trigger.isUpdate){
        for(opportunity opp : trigger.new){
            system.debug('opp'+opp);
            system.debug('opp.Account.name'+opp.Account.name);
            if(opp.Account.name=='Axis'){
             system.debug('opp'+opp);
                opp.amount = opp.amount*10/100;
                //oppIds.add(opp.id);
            }
        }
    //}

}

Hi I am getting null for opp.Account.name when ued system.debug('opp.Account.name'+opp.Account.name);
 Actually iam trying to disount on amount when related account of the opportunity is changed to Axis.
Can some one help me on this?
 

 
 
@istest
public class GSDResourceSkillMappingBatchTest{
    //@isTest(seealldata = false)
    public static testMethod void skillMapTest(){
       
        List<GSD_RDPM_Replication_Detail__c> detailRecords = new list<GSD_RDPM_Replication_Detail__c>();
        
        HPTriggerFrameworkObjectMapping__c trigFramegsdres = new HPTriggerFrameworkObjectMapping__c();
        trigFramegsdres.name = 'GSD_Resource__c';
        trigFramegsdres.DispatcherCalssName__c = 'GSDNewResource';
        
        insert trigFramegsdres;
        
        HPTriggerFrameworkObjectMapping__c objskillmaster= new HPTriggerFrameworkObjectMapping__c();
        objskillmaster.Name='GSD_Skill_Master__c';
        objskillmaster.DispatcherCalssName__c='GSDSKillMaster';
        
        insert objskillmaster;
            
        HPTriggerFrameworkObjectMapping__c objfsm= new HPTriggerFrameworkObjectMapping__c();
        objfsm.Name='CKSW__Skill__c';
        objfsm.DispatcherCalssName__c='GSDFSMSkill';
        
        insert objfsm;
            
        HPTriggerFrameworkObjectMapping__c objsrm= new HPTriggerFrameworkObjectMapping__c();
        objsrm.Name='pse__Skill__c';
        objsrm.DispatcherCalssName__c='GSDSRMSkill';
        
        insert objsrm;    
        
        HPTriggerFrameworkObjectMapping__c trigFrame = new HPTriggerFrameworkObjectMapping__c();
        trigFrame.name = 'CKSW__Engineer_Equipment__c';
        trigFrame.DispatcherCalssName__c = 'GSDResource';
        
        insert trigFrame;
        
        HPTriggerFrameworkObjectMapping__c objgrsm = new HPTriggerFrameworkObjectMapping__c();
        objgrsm.Name='GSD_Resource_Skills_mapping__c';
        objgrsm.DispatcherCalssName__c='GSDResourceSkillMapping';
        
        insert objgrsm;
        
        HPTriggerFrameworkObjectMapping__c mapping = new HPTriggerFrameworkObjectMapping__c();
        mapping.name = 'GSD_Manager_to_District__c';
        mapping.DispatcherCalssName__c = 'GSDManagerToDistrict';
        
        insert mapping;
        
        HPTriggerFrameworkObjectMapping__c psereq = new HPTriggerFrameworkObjectMapping__c();
        psereq.name = 'pse__Resource_Request__c';
        psereq.DispatcherCalssName__c = 'GSDResourceRequest';
        
        insert psereq;
        
        EngineProperties__c ep = new EngineProperties__c(Name='NextUserSet');
        ep.DoubleValue__c = 250;
        ep.Value__c = 'none';
        
        insert ep;
        
        Global_Config__c gc = new Global_Config__c();
        gc.Mute_Triggers__c= false;
        
        insert gc;
        
        GSDResourceMapping__c resmapping = new GSDResourceMapping__c();
        resmapping.name = 'GSD_Mobile_User_Setting__c';
        resmapping .Resource_Field_Name__c = 'CKSW__ClickMobile_User_Setting__c';
        
        insert resmapping ;
        
        GSDResourceMapping__c resmapping1 = new GSDResourceMapping__c();        
        resmapping1.name = 'User__c';       
        resmapping1 .Resource_Field_Name__c = 'CKSW__User__c';      
        
        insert resmapping1 ; 
        
        GSDResourceMapping__c resmapping2 = new GSDResourceMapping__c();
        resmapping2.name = 'GSD_Mobile_User_Setting__c';
        resmapping2.Resource_Field_Name__c = 'CKSW__ClickMobile_User_Setting__c';
        insert resmapping2 ;
        
        GSD_Support_Activity_Mapping__c supportActivity = new GSD_Support_Activity_Mapping__c(name='CSC',Support_Activity__c='Troubleshoot and Resolution (Remote/local)');
        
        insert supportActivity;
        
        UserMatchFields__c uMFObj=new UserMatchFields__c(name='case1',Base__c='case',Label__c='BG',Order__c=1,Path__c='BG__c',Type__c='Picklist');
        
        insert uMFObj;
        
        GSD_Resource_OAE_Mapping__c grem = new GSD_Resource_OAE_Mapping__c();
        grem.Name='CSC_Onshore_Countries__c';
        grem.OAE_Base_Object__c='Case';
        grem.OAE_Parameter__c='Onshore Calculation';
        
        insert grem;
        
        GSD_Resource_OAE_Mapping__c grem1 = new GSD_Resource_OAE_Mapping__c();
        grem1.Name='CSC_Origins_Supported__c';
        grem1.OAE_Base_Object__c='Case';
        grem1.OAE_Parameter__c='Case Origin';
        
        insert grem1;
        
        GSD_Resource_OAE_Mapping__c  grem2 = new GSD_Resource_OAE_Mapping__c();
        grem2.Name='CSC_Routing_Role__c';
        grem2.OAE_Base_Object__c='Case';
        grem2.OAE_Parameter__c='Support Type';
        
        insert grem2;
        
        GSD_Resource_OAE_Mapping__c grem3 = new GSD_Resource_OAE_Mapping__c();
        grem3.Name='CSC_Service_Portfolio__c';
        grem3.OAE_Base_Object__c='Case';
        grem3.OAE_Parameter__c ='Service Portfolio';
        
        insert grem3;
        
        GSD_Resource_OAE_Mapping__c grempriv = new GSD_Resource_OAE_Mapping__c();
        grempriv.Name='CSC_Supports_Private_Cases__c';
        grempriv.OAE_Base_Object__c='Case';
        grempriv.OAE_Parameter__c='Private Case Routing';
        
        insert grempriv;
        
        GSD_Resource_OAE_Mapping__c grem4 = new GSD_Resource_OAE_Mapping__c();
        grem4.Name='CSC_Support_Countries__c';
        grem4.OAE_Base_Object__c='Case';
        grem4.OAE_Parameter__c='Asset Country';
        
        insert grem4;
        
        GSD_Resource_OAE_Mapping__c grem5 = new GSD_Resource_OAE_Mapping__c();
        grem5.Name='Exception Routing Formula';
        grem5.OAE_Base_Object__c='Case';
        grem5.OAE_Parameter__c='Exception Routing Formula';
        
        insert grem5;
        
        GSD_Resource_OAE_Mapping__c gremlang = new GSD_Resource_OAE_Mapping__c(Name='Language');
        gremlang.OAE_Base_Object__c ='Case';
        gremlang.OAE_Parameter__c ='Requestor Language';
        
        insert gremlang;
        
        GSD_Resource_OAE_Mapping__c grem6 = new GSD_Resource_OAE_Mapping__c();
        grem6.Name='Outage__c';
        grem6.OAE_Parameter__c='Outage Routing';
        grem6.OAE_Base_Object__c='Case';
        
        insert grem6;
        
        GSD_Resource_OAE_Mapping__c grem7 = new GSD_Resource_OAE_Mapping__c();
        grem7.Name='pm_oid__c';
        grem7.OAE_Base_Object__c='Case';
        grem7.OAE_Parameter__c='Product Series';
        
        insert grem7;
          
        GSD_Resource_OAE_Mapping__c grem8 = new GSD_Resource_OAE_Mapping__c();
        grem8.Name='Technology';
        grem8.OAE_Base_Object__c='Case';
        grem8.OAE_Parameter__c='Routing Technology';
        
        insert grem8;
        system.assert(grem8.id!=null);
        
        GSD_RDPM__c gsdRdpm= new GSD_RDPM__c();
        gsdRdpm.Name='GSD_RDPM';
        gsdRdpm.Manage_Size__c=2;
        
        insert gsdRdpm;
        
        GSD_RDPM__c clickLimit= new GSD_RDPM__c();
        clickLimit.Name='Click Skill Limit';
        clickLimit.Manage_Size__c=2;
        
        insert clickLimit;
        
        GSD_RDPM__c cscLimit= new GSD_RDPM__c();
        cscLimit.Name='CSC Skill Limit';
        cscLimit.Manage_Size__c=2;
        
        insert cscLimit;
        
        GSD_RDPM__c gsdFSMMute= new GSD_RDPM__c();
        gsdFSMMute.Name='FSM_Skill_Replication';
        gsdFSMMute.Replication_Enable__c=True;
        
        insert gsdFSMMute;
        
        GSD_RDPM__c gsdCSCMute= new  GSD_RDPM__c();
        gsdCSCMute.Name='CSC_Skill_Replication';
        gsdCSCMute.Replication_Enable__c=True;
        
        insert gsdCSCMute;
        
        GSD_RDPM__c batchCustomsetting  = new GSD_RDPM__c();
        batchCustomsetting .Name = 'batch';
        batchCustomsetting.Time_Interval__c = 2;
         
        insert batchCustomsetting;
        
                
        
        }
        
        public static testMethod void skillMapBatchTest(){
        
            skillMapTest();
            Profile cscManagerPro = [SELECT Id, Name FROM Profile WHERE Name = 'GSD CSC Support Engineer Standard' LIMIT 1];        
            User cscProfileUser = new User(profileId = cscManagerPro.id, username = 'hfdsftestemailu98534785834@hp.com', email = 'testemailu98@hp.com',emailencodingkey = 'UTF-8',UserRoleId = UserInfo.getUserRoleId (), localesidkey = 'en_US',languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                           alias='csput78', lastname='lastname8', Adoption_Role_Type__c = 'IT', Email_Address__c = 'testemailu98@hp.com',RMR_Primary_Operational_Role__c = 'Competency Center Engineer');
                
                insert cscProfileUser; 
                system.assert(cscProfileUser.Id!=null);
                
            Profile fsmManagerPro = [SELECT Id, Name FROM Profile WHERE Name = 'GSD FSM Sub Regional Resource' LIMIT 1];        
            User fsmProfileUser = new User( profileId = fsmManagerPro.id, username = 'testemail22ksdhfjkasd@hp.com', email = 'testemail22@hp.com',UserRoleId = UserInfo.getUserRoleId (), 
                                            emailencodingkey = 'UTF-8', localesidkey = 'en_US',languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                            alias='cspu22', lastname='end', Adoption_Role_Type__c = 'IT', Email_Address__c = 'testemail3@hp.com',Legacy_Employee_Ref__c='123451', 
                                            rmr_primary_operational_role__c  = 'Technical Consultant');
                
                insert fsmProfileUser;
            
            Profile srmManagerPro = [SELECT Id FROM Profile WHERE Name='IT Administrator' LIMIT 1];
            User srmProfileUser = new User(profileId = srmManagerPro.id, username = 'test123bbc12@hp.com', email = 'ttKestemail09@hp.com', 
                            emailencodingkey = 'UTF-8', localesidkey = 'en_US',languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                            alias='cspu', lastname='lastname123', Adoption_Role_Type__c = 'IT', Email_Address__c = 'Sjtestemail18@hp.com');
                
            insert srmProfileUser;
            
             GSD_RMR_Roles__c gsdrmrCSC = new GSD_RMR_Roles__c();           
                gsdrmrCSC.name='CSC';
                gsdrmrCSC.RMR_Roles__c='Competency Center Engineer';
                insert gsdrmrCSC;                
            
            GSD_RMR_Roles__c gsdrmrFSM = new GSD_RMR_Roles__c();
                gsdrmrFSM.Name='FSM';
                gsdrmrFSM.RMR_Roles__c='Technical Consultant';
                insert gsdrmrFSM;
            
            GSD_RMR_Roles__c gsdrmrSRM = new GSD_RMR_Roles__c();
                gsdrmrSRM.name='SRM';
                gsdrmrSRM.RMR_Roles__c='Account Support Manager,Technical Consultant,Implementation project manager,Deployment Coordinator,Integration Center Project Manager,Customer Deployment Manager,Deployment Services Engineer,Solution Architect,Account Delivery Manager';
                insert gsdrmrSRM;
            
            GSD_RMR_Roles__c gsdrmrSRM1 = new GSD_RMR_Roles__c();
                gsdrmrSRM1.name='SRM1';
                gsdrmrSRM1.RMR_Roles__c='Account Support Manager';
                insert gsdrmrSRM1;
            UserData__c userData = new UserData__c();
            userData.User__c = cscProfileUser.id;
            insert userData;
            
            UserData__c userData1 = new UserData__c();
            userData1.User__c = fsmProfileUser.id;
            insert userData1;
            
            UserData__c userData2 = new UserData__c();
            userData2.User__c = srmProfileUser.id;
            insert userData2;
            
        
            
            
            World_Region__c newRegion1 = new World_Region__c(Name='AD', Country_Name__c = null);
                insert newRegion1;
            
            GSD_Business_Center__c newBusiness1= new GSD_Business_Center__c(Name='INDIA-INDIA', Business_Center_Key__c=35684933);
                insert newBusiness1;
        

            CKSW__Region__c regionobj1 = new CKSW__Region__c();
                regionobj1.Name='INDIA-INDIA';
                regionobj1.Business_Center__c=newBusiness1.Id;
                insert regionobj1;
                system.debug('regionobj1'+regionobj1);
                
            CKSW__District__c newDistrict1 = new CKSW__District__c();
                newDistrict1.Name = 'Karnataka';
                newDistrict1.CKSW__Region__c=regionobj1.Id;
                insert newDistrict1;
            
            CKSW__Engineer_Equipment__c newResource = new CKSW__Engineer_Equipment__c();
                newResource.Name='Test Eng1';
                newResource.Mobile__c= '(909) 999-9999';
                newResource.Travel_Mode__c = 'ON';
                newResource.Travel_Policy__c='Travel in Company Time';
                newResource.CKSW__User__c= UserInfo.getUserId();
                newResource.CKSW__District__c = newDistrict1.Id;
                newResource.cksw__region__c = regionobj1.Id;          
                insert newResource;
            
            GSD_Manager_to_District__c testManager1 = new GSD_Manager_to_District__c(Name = 'TestManager1', User__c = UserInfo.getUserId(), CKSW_District__c = newDistrict1.Id);    
                insert testManager1;    
            
            World_Region__c WorldRegion = new World_Region__c();
            WorldRegion.name = 'california';
            insert WorldRegion;
            
            String recTypeId = Schema.SObjectType.GSD_Resource__c.getRecordTypeInfosByName().get('FSM/CSC/SRM Engineers').getRecordTypeId();
        if(!Test.isRunningTest()){
            GSD_Resource__c RDPMresource = new GSD_Resource__c(); 
            RDPMresource .recordTypeID = recTypeId ;
            RDPMresource .User__c = fsmProfileUser.Id;
            RDPMresource .Mobile_Phone__c = '8197469999';
            RDPMresource .Country_ISO__c = WorldRegion.Id;
            RDPMresource .CSC_Support_Countries__c = 'Afghanistan;Aland Islands;Albania';      
            RDPMresource .CSC_Service_Portfolio__c = 'Datacenter Care;Datacenter Hyperscale;Contract';         
            RDPMresource .Outage__c = TRUE;        
            RDPMresource .CSC_Routing_Role__c = 'Diagnosis';   
            RDPMresource .Country_Citizenship_ISO_Code__c = WorldRegion.Id;
            RDPMresource .Region__c = regionobj1.Id;
            RDPMresource .Primary_District__c = newDistrict1.Id;
            RDPMresource .Resource_ID__c = '1111';   
            RDPMresource .Active__c = TRUE;
            RDPMresource .FSM_Resource__c = TRUE;
            RDPMresource .SRM_Resource__c=TRUE;    
            
            insert RDPMresource ; 
            
            GSD_Skill_Master__c skill1 = new GSD_Skill_Master__c();        
            skill1.Name='testnonproduct1';
            //skill1.Skill_Type__c='Non-Product';
            skill1.Skill_Name__c='New skill1';
            skill1.Skill_Category__c='Language';
                         
            insert skill1;
            
            GSD_Resource_Skills_mapping__c RDPMresourceSkillsMapping = new GSD_Resource_Skills_mapping__c();
            RDPMresourceSkillsMapping .Skill_Name__c = skill1.Id;
            RDPMresourceSkillsMapping .Standard__c=TRUE;
            RDPMresourceSkillsMapping .Resource_ID__c = RDPMresource .Id;
            RDPMresourceSkillsMapping .Responsibility_Skill_Level__c='0';
            RDPMresourceSkillsMapping .Skill_Category__c = 'Language';
            
            insert RDPMresourceSkillsMapping ; 
            
            
           GSD_RDPM_Replication_Summary__c RDPMreplicationSummary= new GSD_RDPM_Replication_Summary__c();     
           RDPMreplicationSummary.GSD_Resource__c = RDPMresource .Id;
           RDPMreplicationSummary.Event_Type__c = 'Insert';
           RDPMreplicationSummary.CSC__c = TRUE;
           RDPMreplicationSummary.FSM__c = FALSE;
           RDPMreplicationSummary.SRM__C = FALSE;  
            
           insert RDPMreplicationSummary;        
                
          /* GSD_RDPM_Replication_Detail__c RDPMreplicationDetail = new GSD_RDPM_Replication_Detail__c();
           RDPMreplicationDetail .Action__c = 'Info';
           RDPMreplicationDetail .Status__c = 'Completed';
           RDPMreplicationDetail .GSD_Rdpm_Replication_Summary__c = RDPMreplicationSummary.Id;
           RDPMreplicationDetail .GSD_Resource_Skills_mapping__c = RDPMresourceSkillsMapping .Id;
           //gsdrdpmrepdetail1.GSD_Resource_User__c = cscProfileUser.Id;
           RDPMreplicationDetail .Slave_System__c = gsdrmrFSM .Name;
           RDPMreplicationDetail .Slave_System_ID__c = gsdrmrFSM .Id;
            
           insert RDPMreplicationDetail ;*/
           
           GSD_Business_Center__c newBusiness3= new GSD_Business_Center__c(Name='EMEA', Business_Center_Key__c=35684934);
           insert newBusiness3;
           
           CKSW__Region__c regionobj3= new CKSW__Region__c();
           regionobj3.Name='US';
           regionobj3.Business_Center__c=newBusiness3.Id;
           insert regionobj3;
            
           CKSW__District__c newDistrict3= new CKSW__District__c();
           newDistrict3.Name = 'AP';
           newDistrict3.CKSW__Region__c=regionobj3.Id;
           insert newDistrict3;
           
           World_Region__c WorldRegion1 = new World_Region__c();
           WorldRegion1.name = 'Loss angels';
           insert WorldRegion1;
           
           
            GSD_Resource__c RDPMresource1 = new GSD_Resource__c(); 
            RDPMresource1 .recordTypeID = recTypeId ;
            RDPMresource1 .User__c = srmProfileUser .Id;
            RDPMresource1 .Mobile_Phone__c = '8197469999';
            RDPMresource1 .Country_ISO__c = WorldRegion1.Id;
            RDPMresource1 .CSC_Support_Countries__c = 'Afghanistan;Aland Islands;Albania';      
            RDPMresource1 .CSC_Service_Portfolio__c = 'Datacenter Care;Datacenter Hyperscale;Contract';         
            RDPMresource1 .Outage__c = TRUE;        
            RDPMresource1 .CSC_Routing_Role__c = 'Diagnosis';   
            RDPMresource1 .Country_Citizenship_ISO_Code__c = WorldRegion1.Id;
            RDPMresource1 .Region__c = regionobj3.Id;
            RDPMresource1 .Primary_District__c = newDistrict3.Id;
            RDPMresource1 .Resource_ID__c = '1111';   
            RDPMresource1 .Active__c = TRUE;
            RDPMresource1 .FSM_Resource__c = TRUE;
            RDPMresource1 .SRM_Resource__c=TRUE;    
            
            insert RDPMresource1 ; 
           
           GSD_RDPM_Replication_Summary__c RDPMreplicationSummary1= new GSD_RDPM_Replication_Summary__c();   
             
           RDPMreplicationSummary1.GSD_Resource__c = RDPMresource1 .Id;
           RDPMreplicationSummary1.Event_Type__c = 'Insert';
           RDPMreplicationSummary1.CSC__c = TRUE;
           RDPMreplicationSummary1.FSM__c = FALSE;
           RDPMreplicationSummary1.SRM__C = FALSE;  
            
           insert RDPMreplicationSummary1;  
           
           GSD_Business_Center__c newBusiness2= new GSD_Business_Center__c(Name='US', Business_Center_Key__c=35684935);
           insert newBusiness2;
           
           CKSW__Region__c regionobj2= new CKSW__Region__c();
           regionobj2.Name='UK';
           regionobj2.Business_Center__c=newBusiness2.Id;
           insert regionobj2;
            
           CKSW__District__c newDistrict2 = new CKSW__District__c();
           newDistrict2.Name = 'TN';
           newDistrict2.CKSW__Region__c=regionobj2.Id;
           insert newDistrict2;
           
           World_Region__c WorldRegion2 = new World_Region__c();
           WorldRegion2.name = 'Loss angels';
           insert WorldRegion2;
           
          
            
            GSD_Resource__c RDPMresource2 = new GSD_Resource__c(); 
            RDPMresource2 .recordTypeID = recTypeId ;
            RDPMresource2 .User__c = cscProfileUser.Id;
            RDPMresource2 .Mobile_Phone__c = '8197469999';
            RDPMresource2 .Country_ISO__c = WorldRegion2.Id;
            RDPMresource2 .CSC_Support_Countries__c = 'Afghanistan;Aland Islands;Albania';      
            RDPMresource2 .CSC_Service_Portfolio__c = 'Datacenter Care;Datacenter Hyperscale;Contract';         
            RDPMresource2 .Outage__c = TRUE;        
            RDPMresource2 .CSC_Routing_Role__c = 'Diagnosis';   
            RDPMresource2 .Country_Citizenship_ISO_Code__c = WorldRegion.Id;
            RDPMresource2 .Region__c = regionobj1.Id;
            RDPMresource2 .Primary_District__c = newDistrict1.Id;
            RDPMresource2 .Resource_ID__c = '1111';   
            RDPMresource2 .Active__c = TRUE;
            RDPMresource2 .FSM_Resource__c = TRUE;
            RDPMresource2 .SRM_Resource__c=TRUE;    
            
            insert RDPMresource2 ; 
           
           GSD_RDPM_Replication_Summary__c RDPMreplicationSummary2= new GSD_RDPM_Replication_Summary__c();     
           RDPMreplicationSummary2.GSD_Resource__c = RDPMresource2 .Id;
           RDPMreplicationSummary2.Event_Type__c = 'Insert';
           RDPMreplicationSummary2.CSC__c = TRUE;
           RDPMreplicationSummary2.FSM__c = FALSE;
           RDPMreplicationSummary2.SRM__C = FALSE;  
            
           insert RDPMreplicationSummary2;
           
           list<GSD_RDPM_Replication_Detail__c> RDPMreplicationDetailList = new list<GSD_RDPM_Replication_Detail__c>();
           
           
           GSD_RDPM_Replication_Detail__c RDPMreplicationDetail = new GSD_RDPM_Replication_Detail__c();
           RDPMreplicationDetail .Action__c = 'Info';
           RDPMreplicationDetail .Status__c = 'Completed';
           RDPMreplicationDetail .GSD_Rdpm_Replication_Summary__c = RDPMreplicationSummary.Id;
           RDPMreplicationDetail .GSD_Resource_Skills_mapping__c = RDPMresourceSkillsMapping .Id;          
           RDPMreplicationDetail .Slave_System__c = gsdrmrFSM .Name;
           RDPMreplicationDetail .Slave_System_ID__c = gsdrmrFSM .Id;
           RDPMreplicationDetailList .add(RDPMreplicationDetail );       
           insert RDPMreplicationDetail;
           
           GSD_RDPM_Replication_Detail__c RDPMreplicationDetail1 = new GSD_RDPM_Replication_Detail__c();
           RDPMreplicationDetail1.Action__c = 'Info';
           RDPMreplicationDetail1.Status__c = 'Completed';
           RDPMreplicationDetail1.GSD_Rdpm_Replication_Summary__c = RDPMreplicationSummary1.Id;
           RDPMreplicationDetail1.GSD_Resource_Skills_mapping__c = RDPMresourceSkillsMapping .Id;          
           RDPMreplicationDetail1.Slave_System__c = gsdrmrFSM .Name;
           RDPMreplicationDetail1.Slave_System_ID__c = gsdrmrFSM .Id;             
           insert RDPMreplicationDetail1;
           
           GSD_RDPM_Replication_Detail__c RDPMreplicationDetail2 = new GSD_RDPM_Replication_Detail__c();
           RDPMreplicationDetail2.Action__c = 'Info';
           RDPMreplicationDetail2.Status__c = 'Completed';
           RDPMreplicationDetail2.GSD_Rdpm_Replication_Summary__c = RDPMreplicationSummary2.Id;
           RDPMreplicationDetail2.GSD_Resource_Skills_mapping__c = RDPMresourceSkillsMapping .Id;          
           RDPMreplicationDetail2.Slave_System__c = gsdrmrFSM .Name;
           RDPMreplicationDetail2.Slave_System_ID__c = gsdrmrFSM .Id;             
           insert RDPMreplicationDetail2;
           
           RDPMreplicationDetailList.add(RDPMreplicationDetail);
           RDPMreplicationDetailList.add(RDPMreplicationDetail1);
           RDPMreplicationDetailList.add(RDPMreplicationDetail2);
           
           insert RDPMreplicationDetailList;
           
           test.starttest();
           Database.QueryLocator QL;
           Database.BatchableContext BC;
           String GSDResourceQuery = 'SELECT GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.SRM_Resource__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.FSM_Resource__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Email__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.recordTypeID,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.PSA_Account_Name__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.PSA_Geo__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.PSA_Resource_Role__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.PSA_Practice__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.PSA_Work_Calendar__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.RMR_Primary_Operational_Role__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.CSC_Supports_Private_Cases__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.CSC_Origins_Supported__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.CSC_Support_Countries__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Outage__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.CSC_Routing_Role__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.CSC_Service_Portfolio__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.CSC_Resource__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.First_Name__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Last_Name__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Lunch_Start_after_Calendar_Start_sec__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Engineers_start_location_Country__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Travel_Mode__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Employee_ID__c,GSD_Rdpm_Replication_Summary__r.GSD_Resource__r.Travel_to_final_location_included__c,';
           
           GSDResourceQuery+= ' id,Action__c,GSD_Resource_Skills_mapping__c,Slave_System_ID__c ,GSD_Resource_Skills_mapping__r.Click_Service__c,GSD_Resource_User__c,GSD_RDPM_Replication_Summary__r.GSD_Resource__c,Object_Job_Name__c,Status__c,Slave_System__c'+
                    ' from GSD_RDPM_Replication_Detail__c where Status__c=\'Pending\' AND ( Object_Job_Name__c=\'GSD_Resource_Skills_mapping__c\' OR Object_Job_Name__c=\'GSD_Resource__c\')';
               
               GSDResourceSkillMappingBatch   SKMP = new GSDResourceSkillMappingBatch();
               /*SKMP.start(BC);
               SKMP.execute(BC,RDPMreplicationDetailList );
               SKMP.finish(BC);
               
              SKMP.Query =' id,Action__c,GSD_Resource_Skills_mapping__c,Slave_System_ID__c ,GSD_Resource_Skills_mapping__r.Click_Service__c,GSD_Resource_User__c,GSD_RDPM_Replication_Summary__r.GSD_Resource__c,Object_Job_Name__c,Status__c,Slave_System__c'+
   
                    ' from GSD_RDPM_Replication_Detail__c where Status__c=\'Pending\' AND ( Object_Job_Name__c=\'GSD_Resource_Skills_mapping__c\' OR Object_Job_Name__c=\'GSD_Resource__c\')';
       */    
           Database.executeBatch(SKMP );
           test.stoptest();
          }
    }

}

I have written a test class for batch,test methods are passing but it is not covering the code.
trigger abcAccount on Opportunity (before update) {
    list<id> oppIds = new list<id>();
    //if(trigger.isInsert || trigger.isUpdate){
        for(opportunity opp : trigger.new){
            system.debug('opp'+opp);
            system.debug('opp.Account.name'+opp.Account.name);
            if(opp.Account.name=='Axis'){
             system.debug('opp'+opp);
                opp.amount = opp.amount*10/100;
                //oppIds.add(opp.id);
            }
        }
    //}

}

Hi I am getting null for opp.Account.name when ued system.debug('opp.Account.name'+opp.Account.name);
 Actually iam trying to disount on amount when related account of the opportunity is changed to Axis.
Can some one help me on this?
 
I have written a validation rule  as below,

AND( 
$Setup.Global_Config__c.Mute_Validation_Rule__c <> TRUE, 
OR( 
ISBLANK( Account__c ), 
ISBLANK( Name__c ), 
ISPICKVAL( Role__c , ''), 
ISPICKVAL( Role_Scope__c , ''), 
AND( 
ISPICKVAL( Role__c , "Other"), 
LEN(Role_Scope_Description__c) = 0 


)

but when I click save butonn with empty fields , it is not throwing an error, If we select two or mor fileds it i throwing an error,can some one help me on this.
HI I need help in improving the code coverage for the below class.
public  class GSDAccountteammembercontroller {


public list<HPE_Account_Team__c> listofrecords{get;set;}
public Boolean TabToBeClosed {get;set;}
    
public PageReference SaveRecords() 
{
    string parentrecordid = ApexPages.currentPage().getParameters().get('Account__c');
    list<HPE_Account_Team__c> insertlist = new list<HPE_Account_Team__c>();  
    for(HPE_Account_Team__c acctem :listofrecords)
    {
        system.debug('acctem.Name__c'+acctem.Name__c);
        system.debug('parentrecordid'+parentrecordid);
        system.debug('listofrecords'+listofrecords);
        if(acctem.Name__c!=null)
        {
          if(parentrecordid != null && parentrecordid != '')
          acctem.Account__c = parentrecordid ;
          insertlist.add(acctem);
        
        }              
       
    }
        try{
        insert insertlist;
        }
        catch(Exception ex){
         ApexPages.addMessages(ex);
         return null;
        }       
        if(listofrecords!=null){
        listofrecords.clear();
        }
        TabToBeClosed = true;
        return null;

}

public GSDAccountteammembercontroller(ApexPages.StandardController controller){
 HPE_Account_Team__c HPEAccountTeam=(HPE_Account_Team__c)controller.getrecord();
 system.debug('HPEAccountTeam'+HPEAccountTeam);
TabToBeClosed = false;

listofrecords = new list<HPE_Account_Team__c>();
    
    for(Integer i=0; i<5; i++){   
         HPE_Account_Team__c gsdaccteam = new HPE_Account_Team__c();
         gsdaccteam.Account__c=HPEAccountTeam.Account__c;        
         gsdaccteam.Name__c=null;
         gsdaccteam.Role_Scope_Description__c='';
         gsdaccteam.Role__c='';
                 
         listofrecords.add(gsdaccteam);
    
         }
     
} 
  
}

My test class is as below.I am not able to cover the code few lines of the main class, thos lines area as below, find the attachement of screenshot.Screen shot taken from developer console.

 if(acctem.Name__c!=null)
        {
          if(parentrecordid != null && parentrecordid != '')
          acctem.Account__c = parentrecordid ;
          insertlist.add(acctem);
        
        }   
@isTest
public class GSDAccountteammembercontrollerTest{
    private static testMethod void SaveRecordTest(){
        account acc = new account();
        acc.name='test';
        insert acc;
        
        contact con = new contact();
            con.email = 'test@yahoo.com';
            con.Phone__c = '5423515415';
            con.LastName ='last Name';  
        insert con;
        system.debug('con'+con);
        
        HPE_Account_Team__c hpeAccountTeam = new HPE_Account_Team__c();
            hpeAccountTeam.Account__c = acc.id;
            hpeAccountTeam.Name__c = con.id;
            hpeAccountTeam.Role__c = 'Other';
            hpeAccountTeam.Role_Scope__c = 'Global';
            hpeAccountTeam.Role_Scope_Description__c = 'testing';
            hpeAccountTeam.Unique_Key__c = 'dfaafs';
            
            insert hpeAccountTeam;
    
  
        user u = [select id from user where id=:userInfo.getUserId()];
        
        System.runAs(u){
            ApexPages.StandardController con1 = new ApexPages.StandardController(hpeAccountTeam);
            GSDAccountteammembercontroller  teamMemberController = new GSDAccountteammembercontroller(con1);
            teamMemberController.SaveRecords();   
                

        }              
    }
}
Need help in writing test class for the below class


public  class GSDAccountteammembercontroller {

public list<HPE_Account_Team__c> listofrecords{get;set;}
public Boolean displayBOMPopUp {get;set;}
public Boolean TabToBeClosed {get;set;}
    
public PageReference SaveRecords() 
{
system.debug('Method Entry');
    //Id parentrecordid = ApexPages.currentPage().getParameters().get('Id');
    Id parentrecordid = '001G000001IgfGZ';
    list<HPE_Account_Team__c> insertlist = new list<HPE_Account_Team__c>();  
    system.debug('After the Method Entry');
    for(HPE_Account_Team__c acctem :listofrecords)
    {
        system.debug('Entered the for condition'+acctem.Account__c);
        if(acctem.Name__c!=null)
        {
            acctem.Account__c = parentrecordid;
            insertlist.add(acctem);
            system.debug('Method Entry'+insertlist);
        
        }               
       
    }
        try{
        insert insertlist;
        }
        catch(Exception ex){
         //ApexPages.addmessage(new Apexpages.Message(ApexPages.Severity.ERROR, ex.getMessage()));
         ApexPages.addMessages(ex);
         return null;
        }       
        if(listofrecords!=null){
        listofrecords.clear();
        }
        TabToBeClosed = true;
        return null;

}

public GSDAccountteammembercontroller(){
displayBOMPopUp = false;
TabToBeClosed = false;

listofrecords = new list<HPE_Account_Team__c>();
    
    for(Integer i=0; i<5; i++){   
         HPE_Account_Team__c gsdaccteam = new HPE_Account_Team__c();
         gsdaccteam.Account__c=null;
         List<PermissionSetAssignment> UserHasDCDMPerission = new List<PermissionSetAssignment>([SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId= :UserInfo.getUserId() AND PermissionSet.Name = 'GSDAccountDCDMRole']);
         if(UserHasDCDMPerission.size() > 0)
          gsdaccteam.recordtypeid = Schema.SObjectType.HPE_Account_Team__c.getRecordTypeInfosByName().get('DCDM').getRecordTypeId();
        
         gsdaccteam.Name__c=null;
         gsdaccteam.Role_Scope_Description__c='';
         gsdaccteam.Role__c='';
                 
         listofrecords.add(gsdaccteam);
    
         }

     


public void TestActFun(){
    
displayBOMPopUp = true;
}

public void TestPopUp(){

displayBOMPopUp = true;
}

public void closeBOMPopUp() {
    
    displayBOMPopUp = false;

}  
}
Hi I am trying to do Integration between two different organizations in salesforce Using REST API and REST Web Service and Apex Web Service.For safety purpose I did'nt mention my credentials in the below code, actually in my org Iam using all the credentials perfectly, this code was working fine earlier, but now, Iam not abel to get response from the target org.I am getting the error message in the debug log "Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]", I am not able to figure out what is the issue? can some one help me on this.

My debug logs are as follows.
13:38:28.26 (28575173)|USER_DEBUG|[17]|DEBUG|===reqbody== grant_type=password&client_id=3MVG9Y6d_Btp4xp5pS0Mwb345aVwqNmCpRF9rEs1QMG_WkvGPZtIKsyUgujSZPhIcCzzxFQqugJCA7fs7SkZB& client_secret=3594199692394096988&username=manjunath@ceptes.com&password=Surya@12338VnYqobYUKwN718uV5oYB9Hy



13:38:28.26 (162542537)|USER_DEBUG|[19]|DEBUG|===res=== System.HttpResponse[Status=Not Found, StatusCode=404]
 
public class SendAccountFromSource {
    private final String clientId = 'Clent Id from App';
    private final String clientSecret = 'clientSecretfrom connected app';
    private final String username = 'User name';
    private final String password = 'passwordwithsecuritytoken';
public class deserializeResponse{
    public String id;
    public String access_token;
}
public String ReturnAccessToken (SendAccountFromSource acount){
    String reqbody = 'grant_type=password&client_id='+clientId+'& client_secret='+clientSecret+'& username='+username+'&password='+password;
    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setBody(reqbody);
    req.setMethod('POST');
    req.setEndpoint('https://login.salesforce.com/services/oauth2/callback');
    system.debug('===reqbody== '+reqbody);
    HttpResponse res = h.send(req);
    system.debug('===res=== '+res );
    deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
    system.debug('===resp1.access_token== '+resp1.access_token);
    return resp1.access_token;
}
@future(callout=true)
public static void createAccount(String accName, String accId){
    SendAccountFromSource acount = new SendAccountFromSource();
    system.debug('===acount == '+acount );
    String accessToken = acount.ReturnAccessToken (acount);
    system.debug('===accessToken == '+accessToken );
    if(accessToken != null){
    String endPoint = 'https://ap2.salesforce.com/services/data/v32.0/sobjects/Account/';
    String jsonstr = '{"Name" : "' + accName + '"}';
    system.debug('===jsonstr == '+jsonstr );
    Http h2 = new Http();
    HttpRequest req1 = new HttpRequest();
    req1.setHeader('Authorization','Bearer ' + accessToken);
    req1.setHeader('Content-Type','application/json');
    req1.setHeader('accept','application/json');
    req1.setBody(jsonstr);
    req1.setMethod('POST');
    req1.setEndpoint(endPoint);
    HttpResponse res1 = h2.send(req1);
    system.debug('===res1 == '+res1 );
    deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(res1.getbody(),deserializeResponse.class);
    Account a = [SELECT Id FROM Account WHERE Id = :accId];
    system.debug('===a==='+a);
    system.debug('===resp2== '+resp2 );
    system.debug('===jsonstr == '+jsonstr );
    update a;
    }
}
}



 
Users are reporting they cannot post a question.
  • April 13, 2016
  • Like
  • 0