function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anonymous DeveloperAnonymous Developer 

Need help to convert Flow to code

This is the FlowUser-added imageand this is how it runs

Loop CollaborationGroupMemberRequest Status = Pending
Get Account Where ContactId = $Record>UserId>ContactId
Get MembershipGroup Where Group_Id__c contains Loop CollaborationGroup Id
If Account Type Contains MembershipGroup Type{
Id = Loop CollaborationGroupMemberRequest Id 
update Status = Accepted
}else{
create Task update ActivityDate to CurrentDate
}


the bold ones are the objects while the italics are the fields.


Thanks in advance
 
Best Answer chosen by Anonymous Developer
Arun Kumar 1141Arun Kumar 1141

Hi,

You can use this code , hope this will help you.

for(ColloborationGroupMemberRequest request : [SELECT Id, Status, CollaborationGroupId, RequesterId From CollaborationGroupMemberRequest WHERE Status = 'Pending' AND CollaborationGroupId = :collaborationGroupId]){
Account accList = [SELECT Id, type From Account WHERE ContactId = : request.RequesterId];

MembershipGroup__c grp = [SELECT Id, type__c FROM MembershipGroup__c where Group_Id__c LIKE : request. CollaborationGroupId LIMIT 1];

if(accList.Type.contains(grp.Type__c)){
request.Status = 'Accepted';
update request;
}else{
Task taskIns = new Task();
taskIns.OwnerId = UserInfo.getUserId();
taskIns.Subject  = 'Membership request pending';
taskIns.ActivityDate = Date.today();
taskIns.WhatId = request.CollaborationGroupId;
insert taskIns;
}
}

Please mark it as the best answer if it will help you.
Thanks

All Answers

Anonymous DeveloperAnonymous Developer
This is the process:
  • Loop CollaborationGroupMemberRequest Status = Pending
  • Get Account Where ContactId = $Record>UserId>ContactId
  • Get MembershipGroup Where Group_Id__c contains Loop CollaborationGroup Id
  • If Account Type Contains MembershipGroup Type{
    • Id = Loop CollaborationGroupMemberRequest Id 
    • update Status = Accepted
    • }else{
    • create Task update ActivityDate to CurrentDate
    • }


the bold ones are the objects while the italics are the fields.


Thanks in advance
Arun Kumar 1141Arun Kumar 1141

Hi,

You can use this code , hope this will help you.

for(ColloborationGroupMemberRequest request : [SELECT Id, Status, CollaborationGroupId, RequesterId From CollaborationGroupMemberRequest WHERE Status = 'Pending' AND CollaborationGroupId = :collaborationGroupId]){
Account accList = [SELECT Id, type From Account WHERE ContactId = : request.RequesterId];

MembershipGroup__c grp = [SELECT Id, type__c FROM MembershipGroup__c where Group_Id__c LIKE : request. CollaborationGroupId LIMIT 1];

if(accList.Type.contains(grp.Type__c)){
request.Status = 'Accepted';
update request;
}else{
Task taskIns = new Task();
taskIns.OwnerId = UserInfo.getUserId();
taskIns.Subject  = 'Membership request pending';
taskIns.ActivityDate = Date.today();
taskIns.WhatId = request.CollaborationGroupId;
insert taskIns;
}
}

Please mark it as the best answer if it will help you.
Thanks

This was selected as the best answer
Anonymous DeveloperAnonymous Developer
Thanks Arun ... Appreciate the quick reply