• srinivas pulipati
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 9
    Replies
Batch Apex Class:

global class BatchClass implements database.Batchable<Sobject>{
    global database.QueryLocator start(Database.BatchableContext bc){
        String Query='select id from account';
        return Database.getQueryLocator(Query);
    }
    global void execute(Database.BatchableContext bc , List<Sobject> scope){
        List<Account> acc=new List<Account>();      ///These 3 line are not execute  when i run the test code
        for(account a : acc){

            system.debug('a');
            //acc.add(a);
        }
       // update acc;e
    }
    global void finish(Database.BatchableContext bc){
        System.debug('finished');
    }
}

Batch Test Class:

@istest
private class TestBatchClass{
    static testmethod void testbatchclass(){
        BatchClass bc=new BatchClass();
        string Query='select id from account limit 200';
        test.startTest();
        Database.executeBatch(bc,200);
         List<Account> acc=new List<Account>();
         //BatchableContext bc;
        //bc.execute(bc,acc);
        test.stopTest();
    } 
}


When i run the test class code coverage is Show 57%
 
global class CustmerBtach implements database.BatchableContext <sobject>{
    global String name;
    //global String Myname;
    global CustmerBtach(String Myname){
        this.myname =myname;
    }
    global database.QueryLocator start(Database.BatchableContext bc){
        String Query='select id,account_type__c from account where name=+myname';
        return Database.getQueryLocator(Query);
    }
    global void execute(Database.BatchableContext bc,List<Custamer__c> scope){
        List<Custamer__c> cust= new List<Custamer__c>();
        for(Custamer__c c:cust){
            cust.add(c);
        }
        update cust;
    }
    global void finish(Database.BatchableContext bc){
        Messaging.SingleEmailMessage myemail=new messaging.SingleEmailMessage();
        String[] toadd=new String[]{'srinivassfdc3@gmail.com'};
            myemail.setToAddresses(toadd);
             myemail.setSubject('Batch procesed');
            myemail.setplainTextBody('Batch completed sucessfully');
            messaging.sendEmail(new Messaging.Email[]{mymail});
    }
}
}
global class CustmerBtach implements database.BatchableContext <sobject>{
    global String name;
    //global String Myname;
    global CustmerBtach(String Myname){
        this.myname =myname;
    }
    global database.QueryLocator start(Database.BatchableContext bc){
        String Query='select id,account_type__c from account where name=+myname';
        return Database.getQueryLocator(Query);
    }
    global void execute(Database.BatchableContext bc,List<Custamer__c> scope){
        List<Custamer__c> cust= new List<Custamer__c>();
        for(Custamer__c c:cust){
            cust.add(c);
        }
        update cust;
    }
    global void finish(Database.BatchableContext bc){
        Messaging.SingleEmailMessage myemail=new messaging.SingleEmailMessage();
        String[] toadd=new String[]{'srinivassfdc3@gmail.com'};
            myemail.setToAddresses(toadd);
             myemail.setSubject('Batch procesed');
            myemail.setplainTextBody('Batch completed sucessfully');
            messaging.sendEmail(new Messaging.Email[]{mymail});
    }
}
 Error:        Line:27 unexpected token: }



I am create Object API_Name Is: Custamer__c
Hi,

   I created Page for Standard save controller. my page apex code given below...
public class MassEmailMessages {
public final list<id> contactids;
    public list<contact> con;
    public MassEmailMessages(apexpages.StandardController controller){
        con=[select id from contact limit 250];
        for(Integer i=0;i<250;i++){
            contactids.add(con[i].id);
        } 
    }
    public void sendEmail(){
        messaging.MassEmailMessage mail=new messaging.MassEmailMessage();
        mail.setTargetObjectIds(contactids);
        messaging.sendEmail(new messaging.MassEmailMessage[]{mail});
    } 
}

Vf Page:

<apex:page standardController="Contact" extensions="MassEmailMessages">
    <apex:form>
    <apex:commandButton value="sendEmail" action="{!sendEmail}"/>
        </apex:form>
</apex:page>



the above page and class was successfully save without error... and then when i run this page and enter the data then click save button the error given below error is occur...
System.NullPointerException: Attempt to de-reference a null object
Class.MassEmailMessages.<init>: line 7, column 1

 
Apexcode:

public with sharing class relatedcontacts {
public relatedcontacts(){
AccountData();
}
list<Account> lstacc = new list<Account>();
list<accountwrapclass>  lstAccwrap = new list<accountwrapclass>();//[Error] Error: Compile Error: Invalid type: accountwrapclass at line 6 column 47
public list<accountwrapclass> getAccounts() {

// lstacc=[select id,name,phone,website,taxable__c from Account];
return lstAccwrap ;
}
public void AccountData(){
for(Account acc:[select id,name,phone,website from Account]){
accountwrapclass objacc = new accountwrapclass();
objacc.Name = acc.Name;
objacc.accid = acc.id;
objacc.phone = acc.phone;
objacc.website = acc.website;
/*if(acc.taxable__C == true){
objacc.taxable ='yes';
}else{
objacc.taxable ='NO';
}*/
lstAccwrap.add(objAcc);
}
}
}

Vfcode:

<apex:page controller="relatedcontacts">
<script>
function showModal(val){
//window.showModalDialog('/apex/secondpage?id='+val);
window.showModalDialog('/apex/contactswithcheckbox?id='+val);
}
</script>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Records">
<apex:pageBlockTable value="{!Accounts}" var="a">
<apex:column headerValue="Name">
<apex:commandlink value="{!a.Name}" onclick="showModal('{!a.accid}')" />
</apex:column>
<apex:column headerValue="phone" >
{!a.phone}
</apex:column>
<apex:column headerValue="website" >
{!a.website}
</apex:column>
<apex:column headerValue="taxable" >
{!a.taxable}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Apex code:

public class SOSLProgramExample {
    public list<opportunity> optylist{set;get;}
    public list<lead> leadlist{set;get;}
    public list<account> actlist{set;get;}
    public list<contact> conlist{set;get;}
public SOSLProgramExample(){
    
}
public void soslDemo_method(){
  optylist=  new list<opportunity>();
    leadlist=new list<lead>();
    actlist =new list<account>();
    conlist =new list<contact>();
    list<list<sobject>> searchlist=[find 'test' in all fields returning account(id,name,type),contact(name,email),
                                   opportunity(name,stagename),lead(company,name,status)];
    actlist=((list<account>)searchlist[0]);
       conlist=((list<contact>)searchlist[1]);
       leadlist=((list<lead>)searchlist[2]);
       optylist=((list<opportunity>)searchlist[3]);
    
}
}

Vf code:
<apex:page controller="SOSLProgramExample">
    <apex:form>
      <apex:commandButton value="show records using sosl" action="{!sosldemo_method}"/>
        <apex:pageBlock title="accounts">
            <apex:pageBlockTable value="{!actlist}" var="acc">
                <apex:column value="{!acc.name}"/>
                <apex:column  value="{!acc.type}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:pageBlock title="contacts">
           <apex:pageBlockTable value="{!conlist}" var="con">
               <apex:column value="{!con.name}"/>
               <apex:column value="{!con.email}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
       <apex:pageBlock title="leads">
            <apex:pageBlockTable value="{!leadlist}" var="lead">
                <apex:column value="{!lead.name}"/>
                <apex:column value="{!lead.company}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
            <apex:pageBlock title="opportunity">
                <apex:pageBlockTable value="{!optylist}" var="opp">
                    <apex:column value="{!opp.name}"/>
                    <apex:column value="{!opp.stagename}"/>
                </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Visualforce Error:
System.TypeException: Invalid conversion from runtime type List<Opportunity> to List<Lead>
Error is in expression '{!sosldemo_method}' in component <apex:commandButton> in page soslprogramexample: Class.SOSLProgramExample.soslDemo_method: line 18, column 1
Class.SOSLProgramExample.soslDemo_method: line 18, column 1


 
public class TvremoteControll {
    integer volume;
    static final integer MAX_VOLUME=50;
    public TvremoteControll(){
        volume= v;    // Error:Non-void method might not return a value or might have statement after a return statement.
    }
    public integer increaseVolume(integer amount){
        volume t= amount;
        for(volume > MAX_VOLUME){   //Error =expecting an equals sign, found '>'
            volume = MAX_VOLUME;  
            
        }
       return volume;
    }
    public integer decreaseVolume(integer amount){
        volume t1=amount;
        if(volume<0){
            volume=0;
        }
        return volume;
    }
    public static String getMenuOptions(){
        return 'audio settings _ vedio settings';      
    }
}
MyNewBatch:       [this code is correct]

global class MyNewBatch implements Database.Batchable<Sobject> {
    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator('select id,name from account');
    }
    global void execute(Database.BatchableContext bc,list<Sobject> scope){
        List<Account> acc=new List<Account>();
        for(Sobject x:scope ){
           Account a=(Account) x;
            a.name ='Mr'+a.name;
            acc.add(a);
        }
        update acc;
    }
    global void finish(Database.BatchableContext bc){
        
    }
}
MySchedule :  [this program also related to above program tjhis one also corrrect and execute]
global class MySchedule implements Schedulable{
    global void execute(SchedulableContext sc){
        MyNewBatch mb = new MyNewBatch();
        Database.executebatch(mb);
    }
}
TestSchedule :[this program have an error ]
public class TestSchedule {
       public PageReference show(){
           String timeframe ='0 10 8 10 * ?';
        MySchedule ms= new MySchedule();
        System.schedule('MyJob', timeframe, ms); //Error: Non-void method might not return a value or might have statement after a return statement.
       
        }
}

Vf Page:
<apex:page  contentType="TestSchedule">
    <apex:form>
    <apex:commandButton value="click" action="{!show}"/>
    </apex:form>
</apex:page>
BatchApex Class:
global class ContactBatchApex implements DataBase.Batchable<Sobject>{
    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator('select id,phone,account.phone from contact');
    }
    global void execute(Database.BatchableContext bc,list<contact> scope){
        List<contact> con =new List<contact>();
        for(contact c: con){
            c.phone =c.account.phone;
            con.add(c);
        }
        update con;
    }
    global void finish(Database.BatchableContext bc){
        
    }
}

batch:

ContactBatchApex  b=new ContactBatchApex();
database.executebatch(b,1);
Batch Apex Code:
global class BatchApex implements Database.Batchable<sobject> {
    global DataBase.QueryLocator start(DataBase.BatchableContext bc){
        String query ='select id,name from account';
        return DataBase.getQuerylocator(query);
    }
    global void execute(DataBase.BatchableContext bc,List<Account> scope){
        List<Account> acc=new list<Account>();
        for(Account a:scope){
            a.name ='mr.'+a.name;
            scope.add(a);
        }
        update scope;
    }
    global void finish(DataBase.BatchableContext bc){
        
    }
        }

BatchApex b =new BatchApex();
Database.executeQuery(b,5);
Apex code:
public class acclist {
    List<account> acc=new List<Account>();
     public void show(){
    for(integer i=1;i<=4000;i++){
        Account a=new Account(name='UserToday',industry='Banking');
        acc.add(a);
    }
    insert acc;
}
}
Vf Code :

<apex:page  controller="acclist" tabStyle="Account">
    <apex:form>
      <apex:pageBlock title="Create acccount">
         <apex:commandButton value="show" action="{!show}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Error:

System.LimitException: Too many SOQL queries: 101
Error is in expression '{!show}' in component <apex:commandButton> in page acclist: Trigger.AccountInsert: line 3, column 1
Trigger.AccountInsert: line 3, column 1
 
i am already create contact record to the account user but customer portal is not execute.
i am enable the customer portal buttton.but error is came i.e

error:

Portal Account Owner Has No Role
An account owner must be associated with a role to enable portal users or transfer portal users to his or her account. 

please tell me how to create customer portal?
 

public class ListExamples {
    public set<string> name{set;get;}
    public ListExamples(){
        List <string> mylist =new List<String>();
        mylist.add('sakthi');
        mylist.add('sreenu');
        mylist.add('vamsi');
        set<String> name = new set<string>();
        name.add('one');
        name.add('two');
        name.add('three');
        name.addAll('mylist');
    }
    }
Vf Pgae:

<apex:page controller="ListExamples" >
    <apex:form >
        <apex:pageblock >
         <apex:pageBlockTable value="{!name}" var="a">
             <apex:column colspan="2" value="{!a}"/>
        </apex:pageBlockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>


Error:
Method does not exist or incorrect signature: [Set<String>].addAll(String)
Apex:code

public class Example2{
public integer avalue{set;get;}
public integer bvalue{set;get;}
public integer result{set;get;}
public String operation{set;get;}
public pageReference subb(){
result=avalue - bvalue;
operation ='SUBTRACTION';
return null;
}
public pageReference add(){
result = avalue + bvalue;
operation ='ADDITION';
return null;
   }
}

Vf Code:


<apex:page controller="Example2">
<apex:form >
<apex:pageBlock title="caluculator">
<apex:pageBlockSection columns="1" title="simple operation" collapsible="false">
<apex:pageBlockSectionItem >
<apex:outputLabel >enter a value</apex:outputLabel>
<apex:inputText value="{!avalue}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >enter b value</apex:outputLabel>
<apex:inputText value="{!bvalue}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >you have performed {!operation} of{!avalue} and {!bvalue} and result is {!result}</apex:outputLabel> </apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 
Hi all i want a trigger if i change owner of a particular record then we need to notify all the record owners of that object records if any one helps i am very thankfull you
Batch Apex Code:
global class BatchApex implements Database.Batchable<sobject> {
    global DataBase.QueryLocator start(DataBase.BatchableContext bc){
        String query ='select id,name from account';
        return DataBase.getQuerylocator(query);
    }
    global void execute(DataBase.BatchableContext bc,List<Account> scope){
        List<Account> acc=new list<Account>();
        for(Account a:scope){
            a.name ='mr.'+a.name;
            scope.add(a);
        }
        update scope;
    }
    global void finish(DataBase.BatchableContext bc){
        
    }
        }

BatchApex b =new BatchApex();
Database.executeQuery(b,5);
Apexcode:

public with sharing class relatedcontacts {
public relatedcontacts(){
AccountData();
}
list<Account> lstacc = new list<Account>();
list<accountwrapclass>  lstAccwrap = new list<accountwrapclass>();//[Error] Error: Compile Error: Invalid type: accountwrapclass at line 6 column 47
public list<accountwrapclass> getAccounts() {

// lstacc=[select id,name,phone,website,taxable__c from Account];
return lstAccwrap ;
}
public void AccountData(){
for(Account acc:[select id,name,phone,website from Account]){
accountwrapclass objacc = new accountwrapclass();
objacc.Name = acc.Name;
objacc.accid = acc.id;
objacc.phone = acc.phone;
objacc.website = acc.website;
/*if(acc.taxable__C == true){
objacc.taxable ='yes';
}else{
objacc.taxable ='NO';
}*/
lstAccwrap.add(objAcc);
}
}
}

Vfcode:

<apex:page controller="relatedcontacts">
<script>
function showModal(val){
//window.showModalDialog('/apex/secondpage?id='+val);
window.showModalDialog('/apex/contactswithcheckbox?id='+val);
}
</script>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Records">
<apex:pageBlockTable value="{!Accounts}" var="a">
<apex:column headerValue="Name">
<apex:commandlink value="{!a.Name}" onclick="showModal('{!a.accid}')" />
</apex:column>
<apex:column headerValue="phone" >
{!a.phone}
</apex:column>
<apex:column headerValue="website" >
{!a.website}
</apex:column>
<apex:column headerValue="taxable" >
{!a.taxable}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
public class TvremoteControll {
    integer volume;
    static final integer MAX_VOLUME=50;
    public TvremoteControll(){
        volume= v;    // Error:Non-void method might not return a value or might have statement after a return statement.
    }
    public integer increaseVolume(integer amount){
        volume t= amount;
        for(volume > MAX_VOLUME){   //Error =expecting an equals sign, found '>'
            volume = MAX_VOLUME;  
            
        }
       return volume;
    }
    public integer decreaseVolume(integer amount){
        volume t1=amount;
        if(volume<0){
            volume=0;
        }
        return volume;
    }
    public static String getMenuOptions(){
        return 'audio settings _ vedio settings';      
    }
}
MyNewBatch:       [this code is correct]

global class MyNewBatch implements Database.Batchable<Sobject> {
    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator('select id,name from account');
    }
    global void execute(Database.BatchableContext bc,list<Sobject> scope){
        List<Account> acc=new List<Account>();
        for(Sobject x:scope ){
           Account a=(Account) x;
            a.name ='Mr'+a.name;
            acc.add(a);
        }
        update acc;
    }
    global void finish(Database.BatchableContext bc){
        
    }
}
MySchedule :  [this program also related to above program tjhis one also corrrect and execute]
global class MySchedule implements Schedulable{
    global void execute(SchedulableContext sc){
        MyNewBatch mb = new MyNewBatch();
        Database.executebatch(mb);
    }
}
TestSchedule :[this program have an error ]
public class TestSchedule {
       public PageReference show(){
           String timeframe ='0 10 8 10 * ?';
        MySchedule ms= new MySchedule();
        System.schedule('MyJob', timeframe, ms); //Error: Non-void method might not return a value or might have statement after a return statement.
       
        }
}

Vf Page:
<apex:page  contentType="TestSchedule">
    <apex:form>
    <apex:commandButton value="click" action="{!show}"/>
    </apex:form>
</apex:page>
Batch Apex Code:
global class BatchApex implements Database.Batchable<sobject> {
    global DataBase.QueryLocator start(DataBase.BatchableContext bc){
        String query ='select id,name from account';
        return DataBase.getQuerylocator(query);
    }
    global void execute(DataBase.BatchableContext bc,List<Account> scope){
        List<Account> acc=new list<Account>();
        for(Account a:scope){
            a.name ='mr.'+a.name;
            scope.add(a);
        }
        update scope;
    }
    global void finish(DataBase.BatchableContext bc){
        
    }
        }

BatchApex b =new BatchApex();
Database.executeQuery(b,5);

public class ListExamples {
    public set<string> name{set;get;}
    public ListExamples(){
        List <string> mylist =new List<String>();
        mylist.add('sakthi');
        mylist.add('sreenu');
        mylist.add('vamsi');
        set<String> name = new set<string>();
        name.add('one');
        name.add('two');
        name.add('three');
        name.addAll('mylist');
    }
    }
Vf Pgae:

<apex:page controller="ListExamples" >
    <apex:form >
        <apex:pageblock >
         <apex:pageBlockTable value="{!name}" var="a">
             <apex:column colspan="2" value="{!a}"/>
        </apex:pageBlockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>


Error:
Method does not exist or incorrect signature: [Set<String>].addAll(String)
Apex:code

public class Example2{
public integer avalue{set;get;}
public integer bvalue{set;get;}
public integer result{set;get;}
public String operation{set;get;}
public pageReference subb(){
result=avalue - bvalue;
operation ='SUBTRACTION';
return null;
}
public pageReference add(){
result = avalue + bvalue;
operation ='ADDITION';
return null;
   }
}

Vf Code:


<apex:page controller="Example2">
<apex:form >
<apex:pageBlock title="caluculator">
<apex:pageBlockSection columns="1" title="simple operation" collapsible="false">
<apex:pageBlockSectionItem >
<apex:outputLabel >enter a value</apex:outputLabel>
<apex:inputText value="{!avalue}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >enter b value</apex:outputLabel>
<apex:inputText value="{!bvalue}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >you have performed {!operation} of{!avalue} and {!bvalue} and result is {!result}</apex:outputLabel> </apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 
Hi all i want a trigger if i change owner of a particular record then we need to notify all the record owners of that object records if any one helps i am very thankfull you