• Mohidheen N
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
I wants to convet the below string format into csv in Apex, do anyone having any idea or sample apex code to convert into csv document file and save the attachemtn in csv file format in attachment object.

NAICS CODE,LOC #,SUB LOC #,LOCATION NAME,ADDRESS,ADDRESS LINE 2,ADDRESS LINE 3,CITY,STATE/PROVINCE,COUNTY
551114,0,0,,adc,,,ABC,TX,ABCd
531110,2,1,,7729 WESTVIEW DR,,,ABC,TX,ABCd
334513,3,1,AAA-A,1330 WIRT RD,,,ABC,TX,ABCd
334513,3,2,AAA-B,1330 WIRT RD,,,ABC,TX,ABCd

Note: Column header count is ten in the above sample but it may very everytime.
List<UserPackageLicense > llist = new List <UserPackageLicense > ([SELECT id,UserId FROM UserPackageLicense
where PackageLicenseId='05000000000000000']); //- 5000 records

system.debug(llist.size());

Map<ID,Datetime> C_U_map = new Map<ID,Datetime>();

for (UserPackageLicense Ulist: llist){
List<User> C_U_list = new List<User>([select id,LastLoginDate  from User where User.id =:Ulist.UserId]);
C_U_map.put(Ulist.UserId,C_U_list[0].LastLoginDate);

system.debug(C_U_map);
C_U_map.clear();
}

Hi There,

I'm using the above AnonymousBlock and getting governer limits. If i'm using limit clause then code is working fine.

UserPackageLicense having 5000 records how can i retrieve without governer limits.

Can you please suggest?
Hi ,

Can any one help me with the below .

I try to update all te account description with value "Testing 2" in my batches. I tried to update account description by picking 10 10 Acounts, But its updating only first 10 set of records and skipping remainign records.

Can you pls guide me where am wrong.

public class first_batch2_withuser_query implements Database.Batchable<sObject>{

  public final  String Field;
  public final  String Query;
  public final  String Value;
        public first_batch2_withuser_query (String f, String q, String v){
    Field =f;    Query =q;   Value =v;
    }
     public Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(Query);
    }
       public void execute(Database.BatchableContext BC, List<Account> Scope){
    for (Account a: Scope){
    a.put(Field,Value);
        }
    update Scope;    
    }
public void finish(Database.BatchableContext BC){
}
}

I tried with below methods but not updating all the accounts in batches.

String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID batchinstanceID= Database.executeBatch(new first_batch2_withuser_query(f,q,v),5);

​String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID batchinstanceID= Database.executeBatch(new first_batch2_withuser_query(f,q,v));

String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID jobID= Database.executeBatch(new first_batch2_withuser_query(f,q,v));
I wants to convet the below string format into csv in Apex, do anyone having any idea or sample apex code to convert into csv document file and save the attachemtn in csv file format in attachment object.

NAICS CODE,LOC #,SUB LOC #,LOCATION NAME,ADDRESS,ADDRESS LINE 2,ADDRESS LINE 3,CITY,STATE/PROVINCE,COUNTY
551114,0,0,,adc,,,ABC,TX,ABCd
531110,2,1,,7729 WESTVIEW DR,,,ABC,TX,ABCd
334513,3,1,AAA-A,1330 WIRT RD,,,ABC,TX,ABCd
334513,3,2,AAA-B,1330 WIRT RD,,,ABC,TX,ABCd

Note: Column header count is ten in the above sample but it may very everytime.
List<UserPackageLicense > llist = new List <UserPackageLicense > ([SELECT id,UserId FROM UserPackageLicense
where PackageLicenseId='05000000000000000']); //- 5000 records

system.debug(llist.size());

Map<ID,Datetime> C_U_map = new Map<ID,Datetime>();

for (UserPackageLicense Ulist: llist){
List<User> C_U_list = new List<User>([select id,LastLoginDate  from User where User.id =:Ulist.UserId]);
C_U_map.put(Ulist.UserId,C_U_list[0].LastLoginDate);

system.debug(C_U_map);
C_U_map.clear();
}

Hi There,

I'm using the above AnonymousBlock and getting governer limits. If i'm using limit clause then code is working fine.

UserPackageLicense having 5000 records how can i retrieve without governer limits.

Can you please suggest?
Hi ,

Can any one help me with the below .

I try to update all te account description with value "Testing 2" in my batches. I tried to update account description by picking 10 10 Acounts, But its updating only first 10 set of records and skipping remainign records.

Can you pls guide me where am wrong.

public class first_batch2_withuser_query implements Database.Batchable<sObject>{

  public final  String Field;
  public final  String Query;
  public final  String Value;
        public first_batch2_withuser_query (String f, String q, String v){
    Field =f;    Query =q;   Value =v;
    }
     public Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(Query);
    }
       public void execute(Database.BatchableContext BC, List<Account> Scope){
    for (Account a: Scope){
    a.put(Field,Value);
        }
    update Scope;    
    }
public void finish(Database.BatchableContext BC){
}
}

I tried with below methods but not updating all the accounts in batches.

String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID batchinstanceID= Database.executeBatch(new first_batch2_withuser_query(f,q,v),5);

​String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID batchinstanceID= Database.executeBatch(new first_batch2_withuser_query(f,q,v));

String f='Description';
String q= 'Select Description from Account limit 10';
String v='Testing 2';
ID jobID= Database.executeBatch(new first_batch2_withuser_query(f,q,v));