• Anudeep B
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 11
    Replies
Relation Ship
Account (Parent) - Opportunity (Child)
Account (Parent) - Alert (Child)

Question: Is it possible to make a group of records to be executed in same batch in Batch Apex?

Scenario:
10,000 Opportunities will load to the system with below informtion

AccID     OppName     OppDate  
XXXX        Op-x1          4-Mar-2022    
XXXX        Op-x2         4-Mar-2022
YYYY        Op-y1         4-Mar-2022
YYYY        Op-y2          4-Mar-2022


Requirement is, it should create an Alert for the group of same Account and Same OppDate data. 

From the above data it should create 2 Alerts as the data shows two different Accounts on same date.

The challenge here is I couldn't see any control on Batch class to send same set records in one same batch. Any workaround solution for this situation? 
I am trying to complete the one Lightning task i am getting below CSS error, plz help me on this.

User-added image

Thanks
I wrote a test class for this trigger, it is not passed what is the wrong in it?

Trigger:

trigger dupesincont on Lead (before insert, before update) {
    for(lead l: trigger.new)
    {
        if(l.email!=null)
        {
        list<contact> dupcont = [select id,email from contact where email =: l.email];
        string errormessage = 'Name already Exist with this email';
        errormessage += '  Record ID is ' +dupcont[0].id;
        l.addError(errormessage);
        }
    }
}



Test Class:

@isTest
public class trigg_dupesincont {
static testmethod void dupesfind(){

    string aderror;
    contact c = new contact();
    c.lastname = 'Jet Lee';
    c.email = 'Jets@gmail.com';
    insert c;
    

    
    lead l = new lead();
    l.lastname = 'Bruce';
    l.email = 'Jets@gmail.com';
    
        list<contact> cons = [select id,email from contact where email =:l.email];
        if(cons.size()<0)
        {
        system.assertequals(0,cons.size());
        insert l;
        }
        
        else
        {
        system.assertequals('Already in Contact', aderror);
        }
}
}
I am trying to Integrate from one SalesForce to another SalesForce, say SF1(Provider) and SF2(Consumer). I created Connected app and having Consumer key, Consumer Secret and callback URL.

To consume in SF2 i have write this below code.


global class RestTwoStepCall
{
  public string result{set;get;}
  
  public void show()
  {

    Http p = new Http();
    HttpRequest request = new HttpRequest();
    request.setMethod('POST');
    request.setEndPoint('https://login.salesforce.com/services/oauth2/token');
    request.setBody('grant_type=password&client_id=Consumer key(Given) &client_secret=Consumer Secret(Given) &username=UserName(Given)&password=PasswordwithSecurityToken');
    HttpResponse response = p.send(request);
    String resp = response.getBody();
    fromJSON js = (fromJSON)JSON.deserialize(resp,fromJSON.class);
    result = js.access_token;  
    


    HttpRequest req1 = new HttpRequest();
    req1.setMethod('GET');
    req1.setEndPoint('https://ap2.salesforce.com/services/apexrest/Deepus?name=Anudeep&Dept=IT&job=SFDCDeveloper');
    req1.setHeader('Authorization','OAuth '+result);
    HttpResponse res = p.send(req1);
    result = res.getBody();   
    
  }

     public class fromJSON
     {
        public String id;   
        public String issued_at;    
        public String token_type;   
        public String instance_url; 
        public String signature;    
        public String access_token;
        
      }

}



by executing this i got this Error on VF page.. 
[{"message":"Session expired or nvalid","errorCode":"INVALID_SESSION_ID"}]

I have enable api on profile, and did reset security token. where i went wrong.? 
Ihave this JSON :  

public  class Exinteg {
public string result{get;set;}
public Exinteg()
{
    
    JSONGenerator jg = JSON.CreateGenerator(true);
    jg.writestartObject();
    jg.writestringfield('Name','Sathish');
    jg.writeNumberField('age',30);
    jg.writeFieldName('Account');
    list<account> acc= [select name,industry from account limit 2];  
    jg.writeObject(acc);
  // What processing internally at this line 
    jg.writeFieldName('myarray');
    jg.writestartArray();
    jg.writenumber(10);
    jg.writenumber(20);
    jg.writeEndArray();
    jg.writeEndObject();
    result=jg.getAsString();
    
}
}



{ "Name" : "Sathish", "age" : 30, "Account" : [ { "attributes" : { "type" : "Account", "url" : "/services/data/v33.0/sobjects/Account/0019000001Epo6BAAR" }, "Name" : "Sunkeert", "Id" : "0019000001Epo6BAAR", "Industry" : "Chemical" }, { "attributes" : { "type" : "Account", "url" : "/services/data/v33.0/sobjects/Account/0019000001Epo6CAAR" }, "Name" : "Samba", "Id" : "0019000001Epo6CAAR", "Industry" : "Chemical" } ], "myarray" : [ 10, 20 ] }



i was fetching only name and industry fields from account but why the other coming to JSON? which i didn't use in SOQL Query (in bold above).
I have a json which has serialized --> {"make":"Desing","year":2000}
class name is car
  string s = '{"make":"Desing","year":2000}';


i want deserialized explanation for below i did
car c =(car)JSON.deserialize(s,car.class);

for the above line what is the responsibilities of these each word --> (car), (s, car.class)

Calculate function

User will enter Month field and Lifted amount,
i want to calculate Paid Amount, Due Amount, Payable amount.
i tried with formula fields but i didn't success. Please give me idea how to approch on this scenario

i hope image will give you clarity, if not please post me.
Thanks.

I messedup with different answers of batch apex help me on this.


Please correct me below if i go wrong any where.!

/* All in case of batch apex*/
* querylocator ---- will fetch 50 million records.
* one soql query -- will fetch 50000 records.
* getquerylocator-- will fetch 10000 records.
===========================================

Please give me clarification for below.

* How many SOQL queries we can write in a single Batc Apex Class.?
* If we can use more than one SOQLs, can we write on different Objects in the same Batch Apex class.?
* Can SOQL query write in all the methods.(start(), execute(), finish()).?

 Give me clarification on this points, i am confused on these things, even shortly or with explanation.

Thanks.
i am trying to execute below code. where updating a site field in account object.


global class Accbtchstate implements database.batchable<sobject>
{
global database.querylocator start(database.batchablecontext bc)
{
string state = 'select id,name from account';
return database.getquerylocator(state);
}
global void execute(database.batchablecontext bc, list<account> scope)
{
list<account> acc = new list<account>();
for(account a:acc)
{
 a.Site = 'No nedd';
 acc.add(a);
 }
update acc;
}
    
global void finish(database.batchablecontext bc)
{
   
}
}

executing using this:  
1)  Accbtchstate BC = new Accbtchstate();
Database.executeBatch(BC,1000);

please identify problem and guide me how to exactly execute a batch apex.
* i tried all the source to execute.
I created a custom Object "Location" , all are 3 picklists and each other dependent picklists hirarchely.  

User-added image

I am getting Duplication entries from these fields.
when i select HeadQuarter there can be multiple Areas should be enter but once i select one Area in one HeadQuarter,
the selected Area should not save again in the record .

To avoid this which criteria should i follow,

Workflow
Validation Rule
Trigger

Which one is suitable and how.

Is there any other Good Apporach .


 
Field_Integrity_Exception
Failed to create createContainerMember for containerId=1dc900000009PrAAAU: This container member belongs to a container that currently has an unfinished save request with deploymentId=1dr90000000yACy. You may not modify any members in this container until it completes.: Metadata Container ID.


I got this Error While I am trying to Execute My Simple Program. What is it mean, and What is solution for it.
I am trying to complete the one Lightning task i am getting below CSS error, plz help me on this.

User-added image

Thanks
Ihave this JSON :  

public  class Exinteg {
public string result{get;set;}
public Exinteg()
{
    
    JSONGenerator jg = JSON.CreateGenerator(true);
    jg.writestartObject();
    jg.writestringfield('Name','Sathish');
    jg.writeNumberField('age',30);
    jg.writeFieldName('Account');
    list<account> acc= [select name,industry from account limit 2];  
    jg.writeObject(acc);
  // What processing internally at this line 
    jg.writeFieldName('myarray');
    jg.writestartArray();
    jg.writenumber(10);
    jg.writenumber(20);
    jg.writeEndArray();
    jg.writeEndObject();
    result=jg.getAsString();
    
}
}



{ "Name" : "Sathish", "age" : 30, "Account" : [ { "attributes" : { "type" : "Account", "url" : "/services/data/v33.0/sobjects/Account/0019000001Epo6BAAR" }, "Name" : "Sunkeert", "Id" : "0019000001Epo6BAAR", "Industry" : "Chemical" }, { "attributes" : { "type" : "Account", "url" : "/services/data/v33.0/sobjects/Account/0019000001Epo6CAAR" }, "Name" : "Samba", "Id" : "0019000001Epo6CAAR", "Industry" : "Chemical" } ], "myarray" : [ 10, 20 ] }



i was fetching only name and industry fields from account but why the other coming to JSON? which i didn't use in SOQL Query (in bold above).
I messedup with different answers of batch apex help me on this.


Please correct me below if i go wrong any where.!

/* All in case of batch apex*/
* querylocator ---- will fetch 50 million records.
* one soql query -- will fetch 50000 records.
* getquerylocator-- will fetch 10000 records.
===========================================

Please give me clarification for below.

* How many SOQL queries we can write in a single Batc Apex Class.?
* If we can use more than one SOQLs, can we write on different Objects in the same Batch Apex class.?
* Can SOQL query write in all the methods.(start(), execute(), finish()).?

 Give me clarification on this points, i am confused on these things, even shortly or with explanation.

Thanks.
i am trying to execute below code. where updating a site field in account object.


global class Accbtchstate implements database.batchable<sobject>
{
global database.querylocator start(database.batchablecontext bc)
{
string state = 'select id,name from account';
return database.getquerylocator(state);
}
global void execute(database.batchablecontext bc, list<account> scope)
{
list<account> acc = new list<account>();
for(account a:acc)
{
 a.Site = 'No nedd';
 acc.add(a);
 }
update acc;
}
    
global void finish(database.batchablecontext bc)
{
   
}
}

executing using this:  
1)  Accbtchstate BC = new Accbtchstate();
Database.executeBatch(BC,1000);

please identify problem and guide me how to exactly execute a batch apex.
* i tried all the source to execute.
I just want to know what is exactly mean by Alerts & Notifications and what is the difference between them?

Thanks,
Yogi
  • February 11, 2015
  • Like
  • 0
I created a custom Object "Location" , all are 3 picklists and each other dependent picklists hirarchely.  

User-added image

I am getting Duplication entries from these fields.
when i select HeadQuarter there can be multiple Areas should be enter but once i select one Area in one HeadQuarter,
the selected Area should not save again in the record .

To avoid this which criteria should i follow,

Workflow
Validation Rule
Trigger

Which one is suitable and how.

Is there any other Good Apporach .


 

I made a batch class which fetched and updates objects information, and now I'm wondering should I make a trigger to run the batch class or should I make a scheduler class ? Could you give me an example of a trigger that calls a batch and how to create a scheduler class ? I have been reading about them , but I'm not sure what to do and where to start.

 

Thanks!

Laaral

  • August 13, 2013
  • Like
  • 0