String OldUserId = '005D00000023koO'; String NewUserId = '0051i000001KHkT'; //****************Copy Permission Set Assignment******************* List <PermissionSetAssignment> PSAList=[select id,AssigneeId,PermissionSetId,PermissionSet.Name from PermissionSetAssignment where AssigneeId=: OldUserId and PermissionSet.Name like 'XXX%']; List <PermissionSetAssignment> NewPSAList = new List <PermissionSetAssignment>(); set<String> NewPermissionSetId = new set<String> (); List <PermissionSetAssignment> NewPermissionList=[select id,AssigneeId,PermissionSetId,PermissionSet.Name from PermissionSetAssignment where AssigneeId=: NewUserId and PermissionSet.Name like 'XXX%']; for (PermissionSetAssignment PSA :NewPermissionList){ NewPermissionSetId.add(PSA.PermissionSetId); } for (PermissionSetAssignment PSA :PSAList){ if(!NewPermissionSetId.contains(PSA.PermissionSetId )){ PermissionSetAssignment temp = new PermissionSetAssignment(AssigneeId = NewUserId,PermissionSetId = PSA.PermissionSetId ); NewPSAList.add(temp); } } system.debug(NewPSAList); if(NewPSAList.size()>0){ insert NewPSAList; } //***************Public Group******************* List <GroupMember> NewGMList = new List <GroupMember>(); set<String> NewGroupSetId = new set<String> (); List <GroupMember> OldGroupMemberList = [select GroupId,Group.Name,UserOrGroupId from GroupMember where UserOrGroupId =: OldUserId and Group.Name like 'XXX%']; List <GroupMember> NewGroupMemberList = [select GroupId,Group.Name,UserOrGroupId from GroupMember where UserOrGroupId =: NewUserId and Group.Name like 'XXX%']; for(GroupMember gm :NewGroupMemberList ){ NewGroupSetId.add(gm.GroupId ); } for(GroupMember gm :OldGroupMemberList ){ if(!NewGroupSetId.contains(gm.GroupId)){ GroupMember temp = new GroupMember(GroupId = gm.GroupId ,UserOrGroupId = NewUserId ); NewGMList.add(temp); } } insert NewGMList;
如何得到月尾的最后一天?
1 2 3
Date selectedDate = Date.today().addDays(4); Date firstDate = selectedDate.toStartOfMonth(); p.Date__c =firstDate.addDays(date.daysInMonth(selectedDate.year() , selectedDate.month()) - 1);
把string 改为 date
1 2
Date x = Date.valueOf('2015-8-11'); system.debug('Now '+ x );
This also works with Database.upsert for the following signatures: Database.upsert(List records) Database.upsert(List records, SObjectField externalIdField) Database.upsert(List records, Boolean allOrNone) It does not work for the following signature because it causes a compile fail: Database.upsert(List records, SObjectField externalIdField, Boolean allOrNone)
新建File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
publicstaticvoidUploadIntoFile(Blob requestBody,String FileName){ try{ // select id,Title from ContentDocument //String yourFiles = FileBody;//Lets assume this is your binary string of the files'; datetime myDateTime = datetime.now(); ContentVersion conVer = new ContentVersion(); conVer.ContentLocation = 'S'; // S specify this document is in SF, use E for external files conVer.PathOnClient = 'File.txt'; // The files name, extension is very important here which will help the file in preview. conVer.Title = FileName + String.valueOf(myDateTime) ; // Display name of the files conVer.VersionData = requestBody;//EncodingUtil.base64Decode(yourFiles); // converting your binary string to Blog insert conVer; }catch(dmlException e){ system.debug(e.getMessage()); } }