• Giri Kumar B
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 10
    Replies
public class ifsccode_restapi {
public account AccBankDetails;
public string Client_id='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
public string Client_secret='xxxxxxxxxxxxxxxx';
public string Username='xxxxxxxxxxxxxxxx';
public string Passwordd='xxxxxxxxx';
public string getAccessToken(){
Http p=New Http();
string ReqBody='grant_type=password&';
ReqBody=ReqBody+'clientid'+Client_id+'&';
ReqBody=ReqBody+'clientsecret'+Client_secret+'&';
ReqBody=ReqBody+'username'+Username+'&';
ReqBody=ReqBody+'password'+Passwordd+'&';
HttpRequest Req=New HttpRequest();
Req.SetEndpoint('https://login.salesforce.com/services/oauth2/token');
Req.SetMethod('POST');
Req.SetBody(ReqBody);
HttpResponse Res=New HttpResponse();
Res=p.send(Req);
  AccessToken AT=New AccessToken();
        AT=(AccessToken)JSON.deserialize(Res.getBody(), AccessToken.class);
        return AT.access_token;
   
}
public class AccessToken {
public string access_token;
}
public void getBankDetails(string IFSCCode){
string sAccessToken=getAccessToken();
Http p=new Http();
HttpRequest Request=new HttpRequest();
Request.SetEndpoint('?ifsccode='+IFSCCode);
Request.SetMethod('GET');
Request.SetHeader('authorization','bearer'+sAccessToken);
HttpResponse Res=new HttpResponse();
Res=p.send(Request);
System.JSONParser parser = JSON.createParser(Res.getBody());
    System.debug('-------------Access Token -----------'+Res);
AccBankDetails=New account();
while(parser.nextToken()!=null){
if(parser.getText()=='Name'){
parser.nextToken();
AccBankDetails.Name=parser.getText();
}
if(parser.getText()=='Email__c'){
parser.nextToken();
AccBankDetails.Email__c = parser.getText();
}
if(parser.getText()=='Address__c'){
parser.nextToken();
AccBankDetails.Address__c=parser.getText();
}
if(parser.gettext()=='Anniversary_Date__c'){
parser.nextToken();
AccBankDetails.Anniversary_Date__c=parser.getText();
}
if(parser.gettext()=='Languages_Known__c'){
parser.nextToken();
AccBankDetails.Languages_Known__c=parser.getText();
}
if(parser.gettext()=='Mobile_Number__c'){
parser.nextToken();
AccBankDetails.Mobile_Number__c=parser.getText();
}
}
}
}
User-added image
 
I have a requirement to display the record account and contact .  i am writing a wrapper class in account and contact to display record

 my class
   
    public  class conacc {
        public List<MyWrapper> wrapper {get; set;}
      public List<Account> accLst1 {get; set;}
        public List<Contact> conLst1 {get; set;}
        public conacc ()
        {
          accLst1 = [select id,Name from Account  ] ;
           conLst1 = [select Id,Name from contact where AccountId IN : accLst1 ] ;
           wrapper = new List<MyWrapper>() ;
           for(Integer i=0 ; i < 20; i++)
                wrapper.add(new MyWrapper(  conLst1, accLst1[i])) ;
        
        }
    public class MyWrapper
        {
            public Account accRec1 {get; set;}
            public List<Contact> conRec1 {get; set;}
            public MyWrapper( List<Contact> con ,Account acc )
            {
                accRec1 = acc ;
                conRec1 = con ;
            }
    }
    }
    
    i am try to write the test class in wrapper class hit error 
    test class
    
    @istest
    public class wraptest {
    @istest
        public static void mains(){
    /* i am try to record are insert but they are hit error Constructor not defined 
     Which record i am insert for exp:
    account a = new account();
    a.name = "test1";
    insert a;`enter code here`
    i am not understand how to write this wrapper test class
    */
         conacc.MyWrapper  con = new conacc.MyWrapper();
    
    }
    }

 
when the check box is click one the record only That Record only display . But my code is when i check the check box select all the record after dispaly all record . i want only when which one check box click record that record only display 
ApexClass:
public class SetExample{
public List<string> lNames{set;get;}
public List<string> rNames{set;get;}
public boolean flag{set;get;}

public SetExample(){
lNames= new List<string>{'satya','manu','reddy','peeri'};
rNames=new List<string>();
flag=false;
}
public void AddValues(){

for(integer i=0;i<lNames.size();i++)
{
string value;
      if(flag==true)
        {
            value=lNames.get(i);
           rNames.add(value);
           
        }
        
      system.debug(rNames);  
}
}
}

Visual Force Page
<apex:page controller="SetExample">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton value="add" action="{!AddValues}" reRender="one"/>

</apex:pageBlockButtons>

</apex:pageBlock>

<apex:pageblock >

<apex:pageBlockSection >
<apex:pageBlockTable value="{!lNames}" var="n">
<apex:column >

<apex:inputCheckbox value="{!flag}"/>
</apex:column>
<apex:column value="{!n}" />
</apex:pageBlockTable>


<apex:pageBlockTable value="{!rNames}" var="r" id="one">
<apex:column value="{!r}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form> 
{!flag}
</apex:page>    
User-added image
class
--------
public class duplicateerrormsg {
    public static void mains(list<account> acc){
        list<string> a = new list<string>();
        set<string> s = new set<string>();
        for(account at: acc){
            a.add(at.name);
        }
        list<account> acs = [select name from account where name in:a];
        for(account a2:acs){
            s.add(a2.name);
        }
        for(account a3:acc){
            a3.name.adderror('this record has implument ');
        }
    }
}
 
class
---------------
public class textex2 {
public string lastname ;
public string phone;
    public void create(){
        if(phone == '123'){
            account acc = new account();
            acc.name = lastname;
            acc.Phone = phone;
            insert acc;
        }else{
            contact c = new contact();
            c.lastname = 'test1';
            c.phone = '0223';
            insert c;
        }
      
    }
}
------------------------
test
@istest
public class testclassex2 {
@istest
    static void testdata2(){
        textex2 ts = new textex2();
        ts.lastname = 'test1';
        ts.phone = '125';
        ts.create();
        if(ts.phone == '123'){
        integer count = [select count() from account];
            system.assertEquals(count, 1);
            }
        ts.phone ='0234';
        ts.create();
        if(ts.phone != '123'){
            integer size = [select count() from contact];
            system.assertEquals(size,1);
        }
    }
}
I have taken it into the input field and when I created the field set on the opportunity I edited the field set and dropped created date into the field section.
when I am inserted the record save the button showing error :
j_id0:oppForm:oppATPBlock:oppATPBlockSecPart12:j_id29:0:j_id30: An error occurred when processing your submitted information.

Visual Force 
<apex:page standardController="Opportunity" extensions="PSOpportunityController" >
<apex:form id="oppForm">
<apex:pageBlock id="oppATPBlock" mode="inlineEdit"> 
<apex:pageMessages />
<apex:pageBlockButtons location="top">
<apex:commandButton value="Edit" action="{!enableOpportunityEditMode}" rendered="{!NOT(isOpptyEditMode)}"
id="editButton" reRender="oppATPBlock, oppForm" />
<apex:commandButton value="Cancel" action="{!disableOpportunityEditMode}" rendered="{!isOpptyEditMode}"
id="cancelButton" reRender="oppATPBlock, oppForm" />
<apex:commandButton value="Save" action="{!save}" rendered="{!isOpptyEditMode}" />
<!--apex:commandButton value="Save" action="{!saveOpp}" rendered="{!isOpptyEditMode}"
id="saveButton" reRender="oppATPBlock, oppForm" /-->
</apex:pageBlockButtons>
<apex:pageBlockSection id="oppATPBlockSecPart12" columns="2" collapsible="false" rendered="{!isOpptyEditMode}" > 
<apex:repeat value="{!$ObjectType.Opportunity.FieldSets.ATP1_Edit_Fields}" var="fld">
<apex:inputField value="{!oppATP[fld.fieldPath]}"/>
</apex:repeat>
</apex:pageBlockSection>
<apex:pageBlockSection id="blanksection1" columns="2" collapsible="false">
<apex:pageBlockSectionItem />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form> 
</apex:page>
=============
Controller goes this way
=============
public without sharing class PSOpportunityController {
private String oppId {get; set;}
public Boolean isOpptyEditMode { get; set; }
public Opportunity oppATP { get; set; }
public PSOpportunityController (ApexPages.StandardController stdController ) {
oppId = (String)stdController.getId();
isOpptyEditMode = false;
}
/**
* Method is used to enable edit mode on the opportunity object
*/
public void enableOpportunityEditMode(){
isOpptyEditMode = true;
}
/** 
* Method is used to disables the edit mode on the opportunity object
*/ 
public void disableOpportunityEditMode(){
isOpptyEditMode = false;
}
/** 
* Method is used to save the data
*/
public void saveOpp(){
try{ 
update oppATP;
}catch( DmlException dmlEx ){
ApexPages.addMessages( dmlEx );
}
}
}
 
I have a requirement to display the record account and contact .  i am writing a wrapper class in account and contact to display record

 my class
   
    public  class conacc {
        public List<MyWrapper> wrapper {get; set;}
      public List<Account> accLst1 {get; set;}
        public List<Contact> conLst1 {get; set;}
        public conacc ()
        {
          accLst1 = [select id,Name from Account  ] ;
           conLst1 = [select Id,Name from contact where AccountId IN : accLst1 ] ;
           wrapper = new List<MyWrapper>() ;
           for(Integer i=0 ; i < 20; i++)
                wrapper.add(new MyWrapper(  conLst1, accLst1[i])) ;
        
        }
    public class MyWrapper
        {
            public Account accRec1 {get; set;}
            public List<Contact> conRec1 {get; set;}
            public MyWrapper( List<Contact> con ,Account acc )
            {
                accRec1 = acc ;
                conRec1 = con ;
            }
    }
    }
    
    i am try to write the test class in wrapper class hit error 
    test class
    
    @istest
    public class wraptest {
    @istest
        public static void mains(){
    /* i am try to record are insert but they are hit error Constructor not defined 
     Which record i am insert for exp:
    account a = new account();
    a.name = "test1";
    insert a;`enter code here`
    i am not understand how to write this wrapper test class
    */
         conacc.MyWrapper  con = new conacc.MyWrapper();
    
    }
    }

 
class
--------
public class duplicateerrormsg {
    public static void mains(list<account> acc){
        list<string> a = new list<string>();
        set<string> s = new set<string>();
        for(account at: acc){
            a.add(at.name);
        }
        list<account> acs = [select name from account where name in:a];
        for(account a2:acs){
            s.add(a2.name);
        }
        for(account a3:acc){
            a3.name.adderror('this record has implument ');
        }
    }
}
 
class
---------------
public class textex2 {
public string lastname ;
public string phone;
    public void create(){
        if(phone == '123'){
            account acc = new account();
            acc.name = lastname;
            acc.Phone = phone;
            insert acc;
        }else{
            contact c = new contact();
            c.lastname = 'test1';
            c.phone = '0223';
            insert c;
        }
      
    }
}
------------------------
test
@istest
public class testclassex2 {
@istest
    static void testdata2(){
        textex2 ts = new textex2();
        ts.lastname = 'test1';
        ts.phone = '125';
        ts.create();
        if(ts.phone == '123'){
        integer count = [select count() from account];
            system.assertEquals(count, 1);
            }
        ts.phone ='0234';
        ts.create();
        if(ts.phone != '123'){
            integer size = [select count() from contact];
            system.assertEquals(size,1);
        }
    }
}